Zelda Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2023-10-31 08:48:34
Exec Total Coverage
Lines: 1666 4285 38.9%
Functions: 130 332 39.2%
Branches: 924 3042 30.4%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro5/joystick.h"
5 #include "base/qrs.h"
6 #include "base/dmap.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <cstring>
10 #include <math.h>
11 #include <map>
12 #include <filesystem>
13 #include <ctype.h>
14 #include <sstream>
15 #include "base/zc_alleg.h"
16 #include "gamedata.h"
17 #include "zc/zc_init.h"
18 #include "init.h"
19 #include "zc/replay.h"
20 #include "zc/cheats.h"
21 #include "zc/render.h"
22 #include "base/zc_math.h"
23 #include "base/zapp.h"
24 #include "dialog/cheatkeys.h"
25 #include "metadata/metadata.h"
26 #include "zc/zelda.h"
27 #include "zc/saves.h"
28 #include "tiles.h"
29 #include "base/colors.h"
30 #include "pal.h"
31 #include "base/zsys.h"
32 #include "qst.h"
33 #include "zc/zc_sys.h"
34 #include "play_midi.h"
35 #include "gui/jwin_a5.h"
36 #include "base/jwinfsel.h"
37 #include "base/gui.h"
38 #include "midi.h"
39 #include "subscr.h"
40 #include "zc/maps.h"
41 #include "sprite.h"
42 #include "zc/guys.h"
43 #include "zc/hero.h"
44 #include "zc/title.h"
45 #include "particles.h"
46 #include "sound/zcmusic.h"
47 #include "zconsole.h"
48 #include "zc/ffscript.h"
49 #include "dialog/info.h"
50 #include "dialog/alert.h"
51 #include "zc/combos.h"
52 #include "zc/jit.h"
53 #include "zc/zc_subscr.h"
54 #include <fmt/format.h>
55 #include "zinfo.h"
56 #include "base/misctypes.h"
57
58 #ifdef __EMSCRIPTEN__
59 #include "base/emscripten_utils.h"
60 #endif
61
62 using namespace std::chrono_literals;
63
64 extern FFScript FFCore;
65 extern bool Playing;
66 int32_t sfx_voice[WAV_COUNT];
67 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
68 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
69
70 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
71 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
72
73 extern byte monochrome_console;
74
75 extern HeroClass Hero;
76 extern zcmodule moduledata;
77 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
78 extern particle_list particles;
79 extern int32_t loadlast;
80 extern char *sfx_string[WAV_COUNT];
81 byte use_dwm_flush;
82 byte use_save_indicator;
83 int32_t paused_midi_pos = 0;
84 byte midi_suspended = 0;
85 byte zc_192b163_warp_compatibility;
86 char modulepath[2048];
87 bool epilepsyFlashReduction;
88 signed char pause_in_background_menu_init = 0;
89 byte pause_in_background = 0;
90 bool is_sys_pal = false;
91 static bool load_control_called_this_frame;
92 extern PALETTE* hw_palette;
93 extern bool update_hw_pal;
94 extern const char* dmaplist(int32_t index, int32_t* list_size);
95 int32_t getnumber(const char *prompt,int32_t initialval);
96
97 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
98 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
99
100 static const char *qst_module_name = "current_module";
101 #ifdef ALLEGRO_LINUX
102 static const char *samplepath = "samplesoundset/patches.dat";
103 #endif
104 char qst_files_path[2048];
105
106 #ifdef _MSC_VER
107 #define getcwd _getcwd
108 #endif
109
110 bool rF11();
111 bool rI();
112 bool rQ();
113 bool zc_key_pressed();
114
115 #ifdef _WIN32
116
117 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
118 extern "C"
119 {
120 typedef HRESULT(WINAPI *t_DwmFlush)();
121 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
122 }
123
124 void do_DwmFlush()
125 {
126 static HMODULE shell = LoadLibrary("dwmapi.dll");
127
128 if(!shell)
129 return;
130
131 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
132 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
133
134 BOOL enabled;
135 isEnabled(&enabled);
136
137 if(isEnabled)
138 flush();
139 }
140
141 #endif // _WIN32
142
143 83751 bool flash_reduction_enabled(bool check_qr)
144 {
145
4/4
✓ Branch 0 taken 81530 times.
✓ Branch 1 taken 2221 times.
✓ Branch 2 taken 81074 times.
✓ Branch 3 taken 83295 times.
83751 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
146 }
147
148 // Dialogue largening
149 void large_dialog(DIALOG *d)
150 {
151 large_dialog(d, 1.5);
152 }
153
154 void large_dialog(DIALOG *d, float RESIZE_AMT)
155 {
156 if(!d[0].d1)
157 {
158 d[0].d1 = 1;
159 int32_t oldwidth = d[0].w;
160 int32_t oldheight = d[0].h;
161 int32_t oldx = d[0].x;
162 int32_t oldy = d[0].y;
163 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
164 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
165 d[0].w = int32_t(d[0].w*RESIZE_AMT);
166 d[0].h = int32_t(d[0].h*RESIZE_AMT);
167
168 for(int32_t i=1; d[i].proc !=NULL; i++)
169 {
170 // Place elements horizontally
171 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
172 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
173
174 if(d[i].proc != d_stringloader)
175 {
176 if(d[i].proc==d_bitmap_proc)
177 {
178 d[i].w *= 2;
179 }
180 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
181 }
182
183 // Place elements vertically
184 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
185 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
186
187 // Vertically resize elements
188 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
189 {
190 d[i].h = int32_t((double)d[i].h*1.5);
191 }
192 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
193 {
194 d[i].y += int32_t((double)d[i].h*0.25);
195 d[i].h = int32_t((double)d[i].h*1.25);
196 }
197 else if(d[i].proc==d_bitmap_proc)
198 {
199 d[i].h *= 2;
200 }
201 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
202
203 // Fix frames
204 if(d[i].proc == jwin_frame_proc)
205 {
206 d[i].x++;
207 d[i].y++;
208 d[i].w-=4;
209 d[i].h-=4;
210 }
211 }
212 }
213
214 for(int32_t i=1; d[i].proc!=NULL; i++)
215 {
216 if(d[i].proc==jwin_slider_proc)
217 continue;
218
219 // Bigger font
220 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
221
222 if(!d[i].dp2 && bigfontproc)
223 {
224 d[i].dp2 = get_zc_font(font_lfont_l);
225 }
226 else if(!bigfontproc)
227 {
228 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
229 }
230
231 // Make checkboxes work
232 if(d[i].proc == jwin_check_proc)
233 d[i].proc = jwin_checkfont_proc;
234 else if(d[i].proc == jwin_radio_proc)
235 d[i].proc = jwin_radiofont_proc;
236 }
237
238 jwin_center_dialog(d);
239 }
240
241
242 /**********************************/
243 /******** System functions ********/
244 /**********************************/
245
246 static char cfg_sect[] = "zeldadx"; //We need to rename this.
247 static char ctrl_sect[] = "Controls";
248 static char sfx_sect[] = "Volume";
249
250 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
251 {
252 return D_O_K;
253 }
254
255 bool is_reserved_key(int c)
256 {
257 switch(c)
258 {
259 case KEY_ESC:
260 return true;
261 }
262 return false;
263 }
264 bool is_reserved_keycombo(int c, int modflag)
265 {
266 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
267 return true;
268 return false;
269 }
270 bool checkcheat(Cheat cheat)
271 {
272 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
273 return true; //Main key pressed
274 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
275 return true; //Alt key pressed
276 return false;
277 }
278 116 void load_default_cheatkeys()
279 {
280 116 memset(cheatkeys, 0, sizeof(cheatkeys));
281 116 cheatkeys[Cheat::Life][0] = KEY_H;
282 116 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
283 116 cheatkeys[Cheat::Magic][0] = KEY_M;
284 116 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
285 116 cheatkeys[Cheat::Rupies][0] = KEY_R;
286 116 cheatkeys[Cheat::Bombs][0] = KEY_B;
287 116 cheatkeys[Cheat::Arrows][0] = KEY_A;
288 116 cheatkeys[Cheat::Clock][0] = KEY_I;
289 116 cheatkeys[Cheat::Walls][0] = KEY_F11;
290 116 cheatkeys[Cheat::Fast][0] = KEY_Q;
291 116 cheatkeys[Cheat::Light][0] = KEY_L;
292 116 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
293 116 cheatkeys[Cheat::Kill][0] = KEY_K;
294 116 cheatkeys[Cheat::GoTo][0] = KEY_G;
295 116 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
296 116 cheatkeys[Cheat::ShowL0][0] = KEY_0;
297 116 cheatkeys[Cheat::ShowL1][0] = KEY_1;
298 116 cheatkeys[Cheat::ShowL2][0] = KEY_2;
299 116 cheatkeys[Cheat::ShowL3][0] = KEY_3;
300 116 cheatkeys[Cheat::ShowL4][0] = KEY_4;
301 116 cheatkeys[Cheat::ShowL5][0] = KEY_5;
302 116 cheatkeys[Cheat::ShowL6][0] = KEY_6;
303 116 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
304 116 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
305 116 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
306 116 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
307 116 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
308 116 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
309 116 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
310 116 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
311 116 }
312 116 void load_game_configs()
313 {
314 116 strcpy(moduledata.module_name,zc_get_config("ZCMODULE",qst_module_name,"classic.zmod"));
315 116 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
316 116 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
317 116 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
318 116 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
319 116 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
320 116 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
321 116 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
322 116 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
323 116 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
324 116 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
325 116 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
326 116 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
327 116 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
328 116 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
329
330 //cheat modifier keya
331 116 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
332 116 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
333 116 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
334 116 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
335
336 //cheat keys
337 116 load_default_cheatkeys();
338 char buf[256];
339
2/2
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 4060 times.
4176 for(size_t q = 1; q < Cheat::Last; ++q)
340 {
341
1/2
✓ Branch 0 taken 4060 times.
✗ Branch 1 not taken.
4060 if(!bindable_cheat((Cheat)q)) continue;
342 4060 std::string cheatname = cheat_to_string((Cheat)q);
343
1/2
✓ Branch 0 taken 4060 times.
✗ Branch 1 not taken.
4060 util::lowerstr(cheatname);
344 4060 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
345
1/2
✓ Branch 0 taken 4060 times.
✗ Branch 1 not taken.
4060 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
346 4060 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
347
1/2
✓ Branch 0 taken 4060 times.
✗ Branch 1 not taken.
4060 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
348 4060 }
349
350
1/2
✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
116 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
351 joystick_index = 0;
352
353 116 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
354 116 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
355 116 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
356 116 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
357 116 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
358 116 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
359 116 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
360 116 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
361 116 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
362 116 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
363
364 116 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
365 116 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
366 116 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
367 116 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
368
369 116 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
370 116 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
371 116 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
372 116 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
373 116 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
374 116 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
375 116 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
376 116 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
377 116 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
378 116 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
379 116 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
380
381 116 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
382 116 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
383 116 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
384 116 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
385
386 116 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
387
388 116 digi_volume = zc_get_config(sfx_sect,"digi",248);
389 116 midi_volume = zc_get_config(sfx_sect,"midi",255);
390 116 sfx_volume = zc_get_config(sfx_sect,"sfx",248);
391 116 emusic_volume = zc_get_config(sfx_sect,"emusic",248);
392 116 pan_style = zc_get_config(sfx_sect,"pan",1);
393 // 1 <= zcmusic_bufsz <= 128
394 116 zcmusic_bufsz = vbound(zc_get_config(sfx_sect,"zcmusic_bufsz",64),1,128);
395 116 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
396 116 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
397 116 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
398 116 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
399 116 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
400 116 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
401 116 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
402 #ifdef __EMSCRIPTEN__
403 if (em_is_mobile()) NameEntryMode = 2;
404 #endif
405 116 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
406 116 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
407 116 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
408 116 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
409 116 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
410
411 116 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
412 116 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
413 116 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
414 116 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
415 116 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
416 116 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
417 116 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
418
419 116 loadlast = zc_get_config(cfg_sect,"load_last",0);
420
421 116 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
422
423 116 zc_color_depth = (byte) zc_get_config(cfg_sect,"color_depth",8);
424
425 116 forceExit = (byte) zc_get_config(cfg_sect,"force_exit",0);
426 116 info_opacity = zc_get_config("zc","debug_info_opacity",255);
427 #ifdef _WIN32
428 zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
429 zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
430 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
431 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
432
433 // This one's for Aero
434 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
435
436 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
437 #else //UNIX
438 116 zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
439 116 zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
440 116 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
441 #endif
442 116 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
443 116 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
444
445 116 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
446 116 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
447 116 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
448 116 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
449 116 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
450 116 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
451 116 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
452 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
453 116 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1);
454 116 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
455 116 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
456 116 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
457 116 }
458
459 void save_control_configs(bool kb)
460 {
461 if(kb)
462 {
463 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
464 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
465 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
466 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
467
468 if (!replay_is_replaying())
469 {
470 zc_set_config(ctrl_sect,"key_a",Akey);
471 zc_set_config(ctrl_sect,"key_b",Bkey);
472 zc_set_config(ctrl_sect,"key_s",Skey);
473 zc_set_config(ctrl_sect,"key_l",Lkey);
474 zc_set_config(ctrl_sect,"key_r",Rkey);
475 zc_set_config(ctrl_sect,"key_p",Pkey);
476 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
477 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
478 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
479 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
480 zc_set_config(ctrl_sect,"key_up", DUkey);
481 zc_set_config(ctrl_sect,"key_down", DDkey);
482 zc_set_config(ctrl_sect,"key_left", DLkey);
483 zc_set_config(ctrl_sect,"key_right",DRkey);
484 }
485 }
486 else
487 {
488 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
489 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
490 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
491 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
492 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
493 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
494 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
495 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
496 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
497 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
498 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
499 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
500 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
501 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
502
503 zc_set_config(ctrl_sect,"btn_a",Abtn);
504 zc_set_config(ctrl_sect,"btn_b",Bbtn);
505 zc_set_config(ctrl_sect,"btn_s",Sbtn);
506 zc_set_config(ctrl_sect,"btn_m",Mbtn);
507 zc_set_config(ctrl_sect,"btn_l",Lbtn);
508 zc_set_config(ctrl_sect,"btn_r",Rbtn);
509 zc_set_config(ctrl_sect,"btn_p",Pbtn);
510 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
511 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
512 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
513 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
514
515 zc_set_config(ctrl_sect,"btn_up",DUbtn);
516 zc_set_config(ctrl_sect,"btn_down",DDbtn);
517 zc_set_config(ctrl_sect,"btn_left",DLbtn);
518 zc_set_config(ctrl_sect,"btn_right",DRbtn);
519 }
520 }
521
522 void save_cheatkeys()
523 {
524 char buf[256];
525 for(size_t q = 1; q < Cheat::Last; ++q)
526 {
527 if(!bindable_cheat((Cheat)q)) continue;
528 std::string cheatname = cheat_to_string((Cheat)q);
529 util::lowerstr(cheatname);
530 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
531 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
532 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
533 if(cheatkeys[q][1])
534 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
535 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
536 }
537 }
538
539 void save_game_configs()
540 {
541 packfile_password("");
542
543 zc_set_config("ZCMODULE",qst_module_name,moduledata.module_name);
544
545 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
546 {
547 int o_window_x, o_window_y;
548 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
549 zc_set_config(cfg_sect,"window_x",o_window_x);
550 zc_set_config(cfg_sect,"window_y",o_window_y);
551 }
552
553 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
554 {
555 window_width = al_get_display_width(all_get_display());
556 window_height = al_get_display_height(all_get_display());
557 zc_set_config(cfg_sect,"window_width",window_width);
558 zc_set_config(cfg_sect,"window_height",window_height);
559 }
560
561 zc_set_config(cfg_sect,"load_last",loadlast);
562 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
563
564 flush_config_file();
565 #ifdef __EMSCRIPTEN__
566 em_sync_fs();
567 #endif
568 }
569
570 //----------------------------------------------------------------
571
572 // Timers
573
574 32729 void fps_callback()
575 {
576 32729 lastfps=framecnt;
577 32729 framecnt=0;
578 32729 }
579
580 END_OF_FUNCTION(fps_callback)
581
582 116 int32_t Z_init_timers()
583 {
584 static bool didit = false;
585 const static char *err_str = "Couldn't allocate timer";
586 116 err_str = err_str; //Unused variable warning
587
588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
116 if(didit)
589 return 1;
590
591 116 didit = true;
592
593 LOCK_VARIABLE(lastfps);
594 LOCK_VARIABLE(framecnt);
595 LOCK_FUNCTION(fps_callback);
596
597
1/2
✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
116 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
598 return 0;
599
600 116 return 1;
601 116 }
602
603 void Z_remove_timers()
604 {
605 remove_int(fps_callback);
606 }
607
608 //----------------------------------------------------------------
609
610 void go()
611 {
612 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
613 }
614
615 void comeback()
616 {
617 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
618 }
619
620 void dump_pal(BITMAP *dest)
621 {
622 for(int32_t i=0; i<256; i++)
623 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
624 }
625
626 //----------------------------------------------------------------
627
628 int game_mouse_index = ZCM_BLANK;
629 static bool system_mouse = false;
630 28 bool sys_mouse()
631 {
632 28 system_mouse = true;
633 28 return MouseSprite::set(ZCM_NORMAL);
634 }
635 559 bool game_mouse()
636 {
637 559 system_mouse = false;
638 559 return MouseSprite::set(game_mouse_index);
639 }
640 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
641 {
642 if(!bmp)
643 return;
644 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
645 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
646 if(bmp->w == scaledw && bmp->h == scaledh)
647 user_scale = false;
648 if(user_scale || sys_recolor)
649 {
650 if(!user_scale) scale = 1;
651 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
652 if(user_scale)
653 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
654 else
655 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
656 if(sys_recolor)
657 recolor_mouse(tmpbmp);
658 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
659 destroy_bitmap(tmpbmp);
660 }
661 else
662 {
663 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
664 }
665 }
666
667 //Handles converting the mouse sprite from the .dat file
668 void recolor_mouse(BITMAP* bmp)
669 {
670 for(int32_t x = 0; x < bmp->w; ++x)
671 {
672 for(int32_t y = 0; y < bmp->h; ++y)
673 {
674 int32_t color = getpixel(bmp, x, y);
675 switch(color)
676 {
677 case dvc(1):
678 color = jwin_pal[jcCURSORMISC];
679 break;
680 case dvc(2):
681 color = jwin_pal[jcCURSOROUTLINE];
682 break;
683 case dvc(3):
684 color = jwin_pal[jcCURSORLIGHT];
685 break;
686 case dvc(5):
687 color = jwin_pal[jcCURSORDARK];
688 break;
689 default:
690 continue;
691 }
692 putpixel(bmp, x, y, color);
693 }
694 }
695 }
696 void load_mouse()
697 {
698 PALETTE pal;
699 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
700 if (!cursor_bitmap)
701 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
702
703 enter_sys_pal();
704 MouseSprite::set(-1);
705 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
706 int32_t sz = 16*scale;
707 for(int32_t j = 0; j < 1; ++j)
708 {
709 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
710 if(zcmouse[j])
711 destroy_bitmap(zcmouse[j]);
712 zcmouse[j] = create_bitmap_ex(8,sz,sz);
713 clear_bitmap(zcmouse[j]);
714 clear_bitmap(tmpbmp);
715 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
716 recolor_mouse(tmpbmp);
717 if(sz!=16)
718 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
719 else
720 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
721 destroy_bitmap(tmpbmp);
722 }
723 if(!hw_palette) hw_palette = &RAMpal;
724 zc_set_palette(*hw_palette);
725
726 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
727 clear_bitmap(blankmouse);
728
729 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
730 MouseSprite::assign(ZCM_BLANK, blankmouse);
731 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
732
733 //Reload the mouse
734 if(system_mouse)
735 sys_mouse();
736 else game_mouse();
737
738 destroy_bitmap(blankmouse);
739 destroy_bitmap(cursor_bitmap);
740 exit_sys_pal();
741 }
742
743 // sets the video mode and initializes the palette and mouse sprite
744 116 bool game_vid_mode(int32_t mode,int32_t wait)
745 {
746
1/2
✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
116 if (is_headless())
747 116 return true;
748
749 extern int zq_screen_w, zq_screen_h;
750 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
751 {
752 return false;
753 }
754
755 scrx = (resx-320)>>1;
756 scry = (resy-240)>>1;
757 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
758 zcmouse[q] = NULL;
759 load_mouse();
760
761 for(int32_t i=240; i<256; i++)
762 RAMpal[i]=pal_gui[i];
763
764 zc_set_palette(RAMpal);
765 clear_to_color(screen,BLACK);
766
767 rest(wait);
768 return true;
769 116 }
770
771 8 void null_quest()
772 {
773 char qstdat_string[2048];
774 8 strcpy(qstdat_string, "modules/classic/default.qst");
775
776 #ifdef __EMSCRIPTEN__
777 // The quest template data file is not included because it's really big and isn't really needed
778 // for the player, except to initialize some graphics. Those same graphics exist in this quest file,
779 // which is much smaller.
780 strcpy(qstdat_string, "modules/classic/title_gfx.dat");
781 #endif
782
783 8 byte skip_flags[4] = { 0 };
784
785 8 loadquest(qstdat_string,&QHeader,&QMisc,tunes+ZC_MIDI_COUNT,false,skip_flags,0,false);
786 8 }
787
788 8 void init_NES_mode()
789 {
790 8 null_quest();
791 8 }
792
793 //----------------------------------------------------------------
794
795 qword trianglelines[16]=
796 {
797 0x0000000000000000ULL,
798 0xFD00000000000000ULL,
799 0xFDFD000000000000ULL,
800 0xFDFDFD0000000000ULL,
801 0xFDFDFDFD00000000ULL,
802 0xFDFDFDFDFD000000ULL,
803 0xFDFDFDFDFDFD0000ULL,
804 0xFDFDFDFDFDFDFD00ULL,
805 0xFDFDFDFDFDFDFDFDULL,
806 0x00FDFDFDFDFDFDFDULL,
807 0x0000FDFDFDFDFDFDULL,
808 0x000000FDFDFDFDFDULL,
809 0x00000000FDFDFDFDULL,
810 0x0000000000FDFDFDULL,
811 0x000000000000FDFDULL,
812 0x00000000000000FDULL,
813 };
814
815 word screen_triangles[28][32];
816 /*
817 qword triangles[4][16]= //[direction][value]
818 {
819 {
820 0x00000000, 0x10000000, 0x21000000, 0x32100000, 0x43210000, 0x54321000, 0x65432100, 0x76543210, 0x87654321, 0x88765432, 0x88876543, 0x88887654, 0x88888765, 0x88888876, 0x88888887, 0x88888888
821 },
822 {
823 0x00000000, 0xF0000000, 0xEF000000, 0xFDF00000, 0xCFDF0000, 0xBCFDF000, 0xABCFDF00, 0x9ABCFDF0, 0x89ABCFDF, 0x889ABCFD, 0x8889ABCD, 0x88889ABC, 0x888889AB, 0x8888889A, 0x88888889, 0x88888888
824 },
825 {
826 0x00000000, 0x00000001, 0x00000012, 0x00000123, 0x00001234, 0x00012345, 0x00123456, 0x01234567, 0x12345678, 0x23456788, 0x34567888, 0x45678888, 0x56788888, 0x67888888, 0x78888888, 0x88888888
827 },
828 {
829 0x00000000, 0x0000000F, 0x000000FE, 0x00000FED, 0x0000FEDC, 0x000FEDCB, 0x00FEDCBA, 0x0FEDCBA9, 0xFEDCBA98, 0xEDCBA988, 0xDCBA9888, 0xCBA98888, 0xBA988888, 0xA9888888, 0x98888888, 0x88888888
830 }
831 };
832 */
833
834
835 /*
836 byte triangles[4][16][8]= //[direction][value][line]
837 {
838 {
839 {
840 0, 0, 0, 0, 0, 0, 0, 0
841 },
842 {
843 1, 0, 0, 0, 0, 0, 0, 0
844 },
845 {
846 2, 1, 0, 0, 0, 0, 0, 0
847 },
848 {
849 3, 2, 1, 0, 0, 0, 0, 0
850 },
851 {
852 4, 3, 2, 1, 0, 0, 0, 0
853 },
854 {
855 5, 4, 3, 2, 1, 0, 0, 0
856 },
857 {
858 6, 5, 4, 3, 2, 1, 0, 0
859 },
860 {
861 7, 6, 5, 4, 3, 2, 1, 0
862 },
863 {
864 8, 7, 6, 5, 4, 3, 2, 1
865 },
866 {
867 8, 8, 7, 6, 5, 4, 3, 2
868 },
869 {
870 8, 8, 8, 7, 6, 5, 4, 3
871 },
872 {
873 8, 8, 8, 8, 7, 6, 5, 4
874 },
875 {
876 8, 8, 8, 8, 8, 7, 6, 5
877 },
878 {
879 8, 8, 8, 8, 8, 8, 7, 6
880 },
881 {
882 8, 8, 8, 8, 8, 8, 8, 7
883 },
884 {
885 8, 8, 8, 8, 8, 8, 8, 8
886 }
887 },
888 {
889 {
890 0, 0, 0, 0, 0, 0, 0, 0
891 },
892 {
893 15, 0, 0, 0, 0, 0, 0, 0
894 },
895 {
896 14, 15, 0, 0, 0, 0, 0, 0
897 },
898 {
899 13, 14, 15, 0, 0, 0, 0, 0
900 },
901 {
902 12, 13, 14, 15, 0, 0, 0, 0
903 },
904 {
905 11, 12, 13, 14, 15, 0, 0, 0
906 },
907 {
908 10, 11, 12, 13, 14, 15, 0, 0
909 },
910 {
911 9, 10, 11, 12, 13, 14, 15, 0
912 },
913 {
914 8, 9, 10, 11, 12, 13, 14, 15
915 },
916 {
917 8, 8, 9, 10, 11, 12, 13, 14
918 },
919 {
920 8, 8, 8, 9, 10, 11, 12, 13
921 },
922 {
923 8, 8, 8, 8, 9, 10, 11, 12
924 },
925 {
926 8, 8, 8, 8, 8, 9, 10, 11
927 },
928 {
929 8, 8, 8, 8, 8, 8, 9, 10
930 },
931 {
932 8, 8, 8, 8, 8, 8, 8, 9
933 },
934 {
935 8, 8, 8, 8, 8, 8, 8, 8
936 }
937 },
938 {
939 {
940 0, 0, 0, 0, 0, 0, 0, 0
941 },
942 {
943 0, 0, 0, 0, 0, 0, 0, 1
944 },
945 {
946 0, 0, 0, 0, 0, 0, 1, 2
947 },
948 {
949 0, 0, 0, 0, 0, 1, 2, 3
950 },
951 {
952 0, 0, 0, 0, 1, 2, 3, 4
953 },
954 {
955 0, 0, 0, 1, 2, 3, 4, 5
956 },
957 {
958 0, 0, 1, 2, 3, 4, 5, 6
959 },
960 {
961 0, 1, 2, 3, 4, 5, 6, 7
962 },
963 {
964 1, 2, 3, 4, 5, 6, 7, 8
965 },
966 {
967 2, 3, 4, 5, 6, 7, 8, 8
968 },
969 {
970 3, 4, 5, 6, 7, 8, 8, 8
971 },
972 {
973 4, 5, 6, 7, 8, 8, 8, 8
974 },
975 {
976 5, 6, 7, 8, 8, 8, 8, 8
977 },
978 {
979 6, 7, 8, 8, 8, 8, 8, 8
980 },
981 {
982 7, 8, 8, 8, 8, 8, 8, 8
983 },
984 {
985 8, 8, 8, 8, 8, 8, 8, 8
986 }
987 },
988 {
989 {
990 0, 0, 0, 0, 0, 0, 0, 0
991 },
992 {
993 0, 0, 0, 0, 0, 0, 0, 15
994 },
995 {
996 0, 0, 0, 0, 0, 0, 15, 14
997 },
998 {
999 0, 0, 0, 0, 0, 15, 14, 13
1000 },
1001 {
1002 0, 0, 0, 0, 15, 14, 13, 12
1003 },
1004 {
1005 0, 0, 0, 15, 14, 13, 12, 11
1006 },
1007 {
1008 0, 0, 15, 14, 13, 12, 11, 10
1009 },
1010 {
1011 0, 15, 14, 13, 12, 11, 10, 9
1012 },
1013 {
1014 15, 14, 13, 12, 11, 10, 9, 8
1015 },
1016 {
1017 14, 13, 12, 11, 10, 9, 8, 8
1018 },
1019 {
1020 13, 12, 11, 10, 9, 8, 8, 8
1021 },
1022 {
1023 12, 11, 10, 9, 8, 8, 8, 8
1024 },
1025 {
1026 11, 10, 9, 8, 8, 8, 8, 8
1027 },
1028 {
1029 10, 9, 8, 8, 8, 8, 8, 8
1030 },
1031 {
1032 9, 8, 8, 8, 8, 8, 8, 8
1033 },
1034 {
1035 8, 8, 8, 8, 8, 8, 8, 8
1036 }
1037 }
1038 };
1039 */
1040
1041
1042
1043 /*
1044 for (int32_t blockrow=0; blockrow<30; ++i)
1045 {
1046 for (int32_t linerow=0; linerow<8; ++i)
1047 {
1048 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1049 for (int32_t blockcolumn=0; blockcolumn<40; ++i)
1050 {
1051 triangleline=triangles[0][screen_triangles[blockrow][blockcolumn]][linerow];
1052 ++triangleline;
1053 }
1054 }
1055 }
1056 */
1057
1058 // the ULL suffixes are to prevent this warning:
1059 // warning: integer constant is too large for "int32_t" type
1060
1061 qword triangles[4][16][8]= //[direction][value][line]
1062 {
1063 {
1064 {
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL,
1071 0x0000000000000000ULL,
1072 0x0000000000000000ULL
1073 },
1074 {
1075 0xFD00000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL,
1081 0x0000000000000000ULL,
1082 0x0000000000000000ULL
1083 },
1084 {
1085 0xFDFD000000000000ULL,
1086 0xFD00000000000000ULL,
1087 0x0000000000000000ULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL,
1090 0x0000000000000000ULL,
1091 0x0000000000000000ULL,
1092 0x0000000000000000ULL
1093 },
1094 {
1095 0xFDFDFD0000000000ULL,
1096 0xFDFD000000000000ULL,
1097 0xFD00000000000000ULL,
1098 0x0000000000000000ULL,
1099 0x0000000000000000ULL,
1100 0x0000000000000000ULL,
1101 0x0000000000000000ULL,
1102 0x0000000000000000ULL
1103 },
1104 {
1105 0xFDFDFDFD00000000ULL,
1106 0xFDFDFD0000000000ULL,
1107 0xFDFD000000000000ULL,
1108 0xFD00000000000000ULL,
1109 0x0000000000000000ULL,
1110 0x0000000000000000ULL,
1111 0x0000000000000000ULL,
1112 0x0000000000000000ULL
1113 },
1114 {
1115 0xFDFDFDFDFD000000ULL,
1116 0xFDFDFDFD00000000ULL,
1117 0xFDFDFD0000000000ULL,
1118 0xFDFD000000000000ULL,
1119 0xFD00000000000000ULL,
1120 0x0000000000000000ULL,
1121 0x0000000000000000ULL,
1122 0x0000000000000000ULL
1123 },
1124 {
1125 0xFDFDFDFDFDFD0000ULL,
1126 0xFDFDFDFDFD000000ULL,
1127 0xFDFDFDFD00000000ULL,
1128 0xFDFDFD0000000000ULL,
1129 0xFDFD000000000000ULL,
1130 0xFD00000000000000ULL,
1131 0x0000000000000000ULL,
1132 0x0000000000000000ULL
1133 },
1134 {
1135 0xFDFDFDFDFDFDFD00ULL,
1136 0xFDFDFDFDFDFD0000ULL,
1137 0xFDFDFDFDFD000000ULL,
1138 0xFDFDFDFD00000000ULL,
1139 0xFDFDFD0000000000ULL,
1140 0xFDFD000000000000ULL,
1141 0xFD00000000000000ULL,
1142 0x0000000000000000ULL
1143 },
1144 {
1145 0xFDFDFDFDFDFDFDFDULL,
1146 0xFDFDFDFDFDFDFD00ULL,
1147 0xFDFDFDFDFDFD0000ULL,
1148 0xFDFDFDFDFD000000ULL,
1149 0xFDFDFDFD00000000ULL,
1150 0xFDFDFD0000000000ULL,
1151 0xFDFD000000000000ULL,
1152 0xFD00000000000000ULL
1153 },
1154 {
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0xFDFDFDFDFDFDFDFDULL,
1157 0xFDFDFDFDFDFDFD00ULL,
1158 0xFDFDFDFDFDFD0000ULL,
1159 0xFDFDFDFDFD000000ULL,
1160 0xFDFDFDFD00000000ULL,
1161 0xFDFDFD0000000000ULL,
1162 0xFDFD000000000000ULL
1163 },
1164 {
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0xFDFDFDFDFDFDFDFDULL,
1168 0xFDFDFDFDFDFDFD00ULL,
1169 0xFDFDFDFDFDFD0000ULL,
1170 0xFDFDFDFDFD000000ULL,
1171 0xFDFDFDFD00000000ULL,
1172 0xFDFDFD0000000000ULL
1173 },
1174 {
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0xFDFDFDFDFDFDFD00ULL,
1180 0xFDFDFDFDFDFD0000ULL,
1181 0xFDFDFDFDFD000000ULL,
1182 0xFDFDFDFD00000000ULL
1183 },
1184 {
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0xFDFDFDFDFDFDFD00ULL,
1191 0xFDFDFDFDFDFD0000ULL,
1192 0xFDFDFDFDFD000000ULL
1193 },
1194 {
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL,
1200 0xFDFDFDFDFDFDFDFDULL,
1201 0xFDFDFDFDFDFDFD00ULL,
1202 0xFDFDFDFDFDFD0000ULL
1203 },
1204 {
1205 0xFDFDFDFDFDFDFDFDULL,
1206 0xFDFDFDFDFDFDFDFDULL,
1207 0xFDFDFDFDFDFDFDFDULL,
1208 0xFDFDFDFDFDFDFDFDULL,
1209 0xFDFDFDFDFDFDFDFDULL,
1210 0xFDFDFDFDFDFDFDFDULL,
1211 0xFDFDFDFDFDFDFDFDULL,
1212 0xFDFDFDFDFDFDFD00ULL
1213 },
1214 {
1215 0xFDFDFDFDFDFDFDFDULL,
1216 0xFDFDFDFDFDFDFDFDULL,
1217 0xFDFDFDFDFDFDFDFDULL,
1218 0xFDFDFDFDFDFDFDFDULL,
1219 0xFDFDFDFDFDFDFDFDULL,
1220 0xFDFDFDFDFDFDFDFDULL,
1221 0xFDFDFDFDFDFDFDFDULL,
1222 0xFDFDFDFDFDFDFDFDULL
1223 }
1224 },
1225 {
1226 {
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0x0000000000000000ULL,
1231 0x0000000000000000ULL,
1232 0x0000000000000000ULL,
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL
1235 },
1236 {
1237 0x00000000000000FDULL,
1238 0x0000000000000000ULL,
1239 0x0000000000000000ULL,
1240 0x0000000000000000ULL,
1241 0x0000000000000000ULL,
1242 0x0000000000000000ULL,
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL
1245 },
1246 {
1247 0x000000000000FDFDULL,
1248 0x00000000000000FDULL,
1249 0x0000000000000000ULL,
1250 0x0000000000000000ULL,
1251 0x0000000000000000ULL,
1252 0x0000000000000000ULL,
1253 0x0000000000000000ULL,
1254 0x0000000000000000ULL
1255 },
1256 {
1257 0x0000000000FDFDFDULL,
1258 0x000000000000FDFDULL,
1259 0x00000000000000FDULL,
1260 0x0000000000000000ULL,
1261 0x0000000000000000ULL,
1262 0x0000000000000000ULL,
1263 0x0000000000000000ULL,
1264 0x0000000000000000ULL
1265 },
1266 {
1267 0x00000000FDFDFDFDULL,
1268 0x0000000000FDFDFDULL,
1269 0x000000000000FDFDULL,
1270 0x00000000000000FDULL,
1271 0x0000000000000000ULL,
1272 0x0000000000000000ULL,
1273 0x0000000000000000ULL,
1274 0x0000000000000000ULL
1275 },
1276 {
1277 0x000000FDFDFDFDFDULL,
1278 0x00000000FDFDFDFDULL,
1279 0x0000000000FDFDFDULL,
1280 0x000000000000FDFDULL,
1281 0x00000000000000FDULL,
1282 0x0000000000000000ULL,
1283 0x0000000000000000ULL,
1284 0x0000000000000000ULL
1285 },
1286 {
1287 0x0000FDFDFDFDFDFDULL,
1288 0x000000FDFDFDFDFDULL,
1289 0x00000000FDFDFDFDULL,
1290 0x0000000000FDFDFDULL,
1291 0x000000000000FDFDULL,
1292 0x00000000000000FDULL,
1293 0x0000000000000000ULL,
1294 0x0000000000000000ULL
1295 },
1296 {
1297 0x00FDFDFDFDFDFDFDULL,
1298 0x0000FDFDFDFDFDFDULL,
1299 0x000000FDFDFDFDFDULL,
1300 0x00000000FDFDFDFDULL,
1301 0x0000000000FDFDFDULL,
1302 0x000000000000FDFDULL,
1303 0x00000000000000FDULL,
1304 0x0000000000000000ULL
1305 },
1306 {
1307 0xFDFDFDFDFDFDFDFDULL,
1308 0x00FDFDFDFDFDFDFDULL,
1309 0x0000FDFDFDFDFDFDULL,
1310 0x000000FDFDFDFDFDULL,
1311 0x00000000FDFDFDFDULL,
1312 0x0000000000FDFDFDULL,
1313 0x000000000000FDFDULL,
1314 0x00000000000000FDULL
1315 },
1316 {
1317 0xFDFDFDFDFDFDFDFDULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0x00FDFDFDFDFDFDFDULL,
1320 0x0000FDFDFDFDFDFDULL,
1321 0x000000FDFDFDFDFDULL,
1322 0x00000000FDFDFDFDULL,
1323 0x0000000000FDFDFDULL,
1324 0x000000000000FDFDULL
1325 },
1326 {
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0x00FDFDFDFDFDFDFDULL,
1331 0x0000FDFDFDFDFDFDULL,
1332 0x000000FDFDFDFDFDULL,
1333 0x00000000FDFDFDFDULL,
1334 0x0000000000FDFDFDULL
1335 },
1336 {
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0x00FDFDFDFDFDFDFDULL,
1342 0x0000FDFDFDFDFDFDULL,
1343 0x000000FDFDFDFDFDULL,
1344 0x00000000FDFDFDFDULL
1345 },
1346 {
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0x00FDFDFDFDFDFDFDULL,
1353 0x0000FDFDFDFDFDFDULL,
1354 0x000000FDFDFDFDFDULL
1355 },
1356 {
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL,
1362 0xFDFDFDFDFDFDFDFDULL,
1363 0x00FDFDFDFDFDFDFDULL,
1364 0x0000FDFDFDFDFDFDULL
1365 },
1366 {
1367 0xFDFDFDFDFDFDFDFDULL,
1368 0xFDFDFDFDFDFDFDFDULL,
1369 0xFDFDFDFDFDFDFDFDULL,
1370 0xFDFDFDFDFDFDFDFDULL,
1371 0xFDFDFDFDFDFDFDFDULL,
1372 0xFDFDFDFDFDFDFDFDULL,
1373 0xFDFDFDFDFDFDFDFDULL,
1374 0x00FDFDFDFDFDFDFDULL
1375 },
1376 {
1377 0xFDFDFDFDFDFDFDFDULL,
1378 0xFDFDFDFDFDFDFDFDULL,
1379 0xFDFDFDFDFDFDFDFDULL,
1380 0xFDFDFDFDFDFDFDFDULL,
1381 0xFDFDFDFDFDFDFDFDULL,
1382 0xFDFDFDFDFDFDFDFDULL,
1383 0xFDFDFDFDFDFDFDFDULL,
1384 0xFDFDFDFDFDFDFDFDULL
1385 }
1386 },
1387 {
1388 {
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x0000000000000000ULL,
1393 0x0000000000000000ULL,
1394 0x0000000000000000ULL,
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL
1397 },
1398 {
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x0000000000000000ULL,
1402 0x0000000000000000ULL,
1403 0x0000000000000000ULL,
1404 0x0000000000000000ULL,
1405 0x0000000000000000ULL,
1406 0xFD00000000000000ULL
1407 },
1408 {
1409 0x0000000000000000ULL,
1410 0x0000000000000000ULL,
1411 0x0000000000000000ULL,
1412 0x0000000000000000ULL,
1413 0x0000000000000000ULL,
1414 0x0000000000000000ULL,
1415 0xFD00000000000000ULL,
1416 0xFDFD000000000000ULL
1417 },
1418 {
1419 0x0000000000000000ULL,
1420 0x0000000000000000ULL,
1421 0x0000000000000000ULL,
1422 0x0000000000000000ULL,
1423 0x0000000000000000ULL,
1424 0xFD00000000000000ULL,
1425 0xFDFD000000000000ULL,
1426 0xFDFDFD0000000000ULL
1427 },
1428 {
1429 0x0000000000000000ULL,
1430 0x0000000000000000ULL,
1431 0x0000000000000000ULL,
1432 0x0000000000000000ULL,
1433 0xFD00000000000000ULL,
1434 0xFDFD000000000000ULL,
1435 0xFDFDFD0000000000ULL,
1436 0xFDFDFDFD00000000ULL
1437 },
1438 {
1439 0x0000000000000000ULL,
1440 0x0000000000000000ULL,
1441 0x0000000000000000ULL,
1442 0xFD00000000000000ULL,
1443 0xFDFD000000000000ULL,
1444 0xFDFDFD0000000000ULL,
1445 0xFDFDFDFD00000000ULL,
1446 0xFDFDFDFDFD000000ULL
1447 },
1448 {
1449 0x0000000000000000ULL,
1450 0x0000000000000000ULL,
1451 0xFD00000000000000ULL,
1452 0xFDFD000000000000ULL,
1453 0xFDFDFD0000000000ULL,
1454 0xFDFDFDFD00000000ULL,
1455 0xFDFDFDFDFD000000ULL,
1456 0xFDFDFDFDFDFD0000ULL
1457 },
1458 {
1459 0x0000000000000000ULL,
1460 0xFD00000000000000ULL,
1461 0xFDFD000000000000ULL,
1462 0xFDFDFD0000000000ULL,
1463 0xFDFDFDFD00000000ULL,
1464 0xFDFDFDFDFD000000ULL,
1465 0xFDFDFDFDFDFD0000ULL,
1466 0xFDFDFDFDFDFDFD00ULL
1467 },
1468 {
1469 0xFD00000000000000ULL,
1470 0xFDFD000000000000ULL,
1471 0xFDFDFD0000000000ULL,
1472 0xFDFDFDFD00000000ULL,
1473 0xFDFDFDFDFD000000ULL,
1474 0xFDFDFDFDFDFD0000ULL,
1475 0xFDFDFDFDFDFDFD00ULL,
1476 0xFDFDFDFDFDFDFDFDULL
1477 },
1478 {
1479 0xFDFD000000000000ULL,
1480 0xFDFDFD0000000000ULL,
1481 0xFDFDFDFD00000000ULL,
1482 0xFDFDFDFDFD000000ULL,
1483 0xFDFDFDFDFDFD0000ULL,
1484 0xFDFDFDFDFDFDFD00ULL,
1485 0xFDFDFDFDFDFDFDFDULL,
1486 0xFDFDFDFDFDFDFDFDULL
1487 },
1488 {
1489 0xFDFDFD0000000000ULL,
1490 0xFDFDFDFD00000000ULL,
1491 0xFDFDFDFDFD000000ULL,
1492 0xFDFDFDFDFDFD0000ULL,
1493 0xFDFDFDFDFDFDFD00ULL,
1494 0xFDFDFDFDFDFDFDFDULL,
1495 0xFDFDFDFDFDFDFDFDULL,
1496 0xFDFDFDFDFDFDFDFDULL
1497 },
1498 {
1499 0xFDFDFDFD00000000ULL,
1500 0xFDFDFDFDFD000000ULL,
1501 0xFDFDFDFDFDFD0000ULL,
1502 0xFDFDFDFDFDFDFD00ULL,
1503 0xFDFDFDFDFDFDFDFDULL,
1504 0xFDFDFDFDFDFDFDFDULL,
1505 0xFDFDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL
1507 },
1508 {
1509 0xFDFDFDFDFD000000ULL,
1510 0xFDFDFDFDFDFD0000ULL,
1511 0xFDFDFDFDFDFDFD00ULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL
1517 },
1518 {
1519 0xFDFDFDFDFDFD0000ULL,
1520 0xFDFDFDFDFDFDFD00ULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL,
1524 0xFDFDFDFDFDFDFDFDULL,
1525 0xFDFDFDFDFDFDFDFDULL,
1526 0xFDFDFDFDFDFDFDFDULL
1527 },
1528 {
1529 0xFDFDFDFDFDFDFD00ULL,
1530 0xFDFDFDFDFDFDFDFDULL,
1531 0xFDFDFDFDFDFDFDFDULL,
1532 0xFDFDFDFDFDFDFDFDULL,
1533 0xFDFDFDFDFDFDFDFDULL,
1534 0xFDFDFDFDFDFDFDFDULL,
1535 0xFDFDFDFDFDFDFDFDULL,
1536 0xFDFDFDFDFDFDFDFDULL
1537 },
1538 {
1539 0xFDFDFDFDFDFDFDFDULL,
1540 0xFDFDFDFDFDFDFDFDULL,
1541 0xFDFDFDFDFDFDFDFDULL,
1542 0xFDFDFDFDFDFDFDFDULL,
1543 0xFDFDFDFDFDFDFDFDULL,
1544 0xFDFDFDFDFDFDFDFDULL,
1545 0xFDFDFDFDFDFDFDFDULL,
1546 0xFDFDFDFDFDFDFDFDULL
1547 }
1548 },
1549 {
1550 {
1551 0x0000000000000000ULL,
1552 0x0000000000000000ULL,
1553 0x0000000000000000ULL,
1554 0x0000000000000000ULL,
1555 0x0000000000000000ULL,
1556 0x0000000000000000ULL,
1557 0x0000000000000000ULL,
1558 0x0000000000000000ULL
1559 },
1560 {
1561 0x0000000000000000ULL,
1562 0x0000000000000000ULL,
1563 0x0000000000000000ULL,
1564 0x0000000000000000ULL,
1565 0x0000000000000000ULL,
1566 0x0000000000000000ULL,
1567 0x0000000000000000ULL,
1568 0x00000000000000FDULL
1569 },
1570 {
1571 0x0000000000000000ULL,
1572 0x0000000000000000ULL,
1573 0x0000000000000000ULL,
1574 0x0000000000000000ULL,
1575 0x0000000000000000ULL,
1576 0x0000000000000000ULL,
1577 0x00000000000000FDULL,
1578 0x000000000000FDFDULL
1579 },
1580 {
1581 0x0000000000000000ULL,
1582 0x0000000000000000ULL,
1583 0x0000000000000000ULL,
1584 0x0000000000000000ULL,
1585 0x0000000000000000ULL,
1586 0x00000000000000FDULL,
1587 0x000000000000FDFDULL,
1588 0x0000000000FDFDFDULL
1589 },
1590 {
1591 0x0000000000000000ULL,
1592 0x0000000000000000ULL,
1593 0x0000000000000000ULL,
1594 0x0000000000000000ULL,
1595 0x00000000000000FDULL,
1596 0x000000000000FDFDULL,
1597 0x0000000000FDFDFDULL,
1598 0x00000000FDFDFDFDULL
1599 },
1600 {
1601 0x0000000000000000ULL,
1602 0x0000000000000000ULL,
1603 0x0000000000000000ULL,
1604 0x00000000000000FDULL,
1605 0x000000000000FDFDULL,
1606 0x0000000000FDFDFDULL,
1607 0x00000000FDFDFDFDULL,
1608 0x000000FDFDFDFDFDULL
1609 },
1610 {
1611 0x0000000000000000ULL,
1612 0x0000000000000000ULL,
1613 0x00000000000000FDULL,
1614 0x000000000000FDFDULL,
1615 0x0000000000FDFDFDULL,
1616 0x00000000FDFDFDFDULL,
1617 0x000000FDFDFDFDFDULL,
1618 0x0000FDFDFDFDFDFDULL
1619 },
1620 {
1621 0x0000000000000000ULL,
1622 0x00000000000000FDULL,
1623 0x000000000000FDFDULL,
1624 0x0000000000FDFDFDULL,
1625 0x00000000FDFDFDFDULL,
1626 0x000000FDFDFDFDFDULL,
1627 0x0000FDFDFDFDFDFDULL,
1628 0x00FDFDFDFDFDFDFDULL
1629 },
1630 {
1631 0x00000000000000FDULL,
1632 0x000000000000FDFDULL,
1633 0x0000000000FDFDFDULL,
1634 0x00000000FDFDFDFDULL,
1635 0x000000FDFDFDFDFDULL,
1636 0x0000FDFDFDFDFDFDULL,
1637 0x00FDFDFDFDFDFDFDULL,
1638 0xFDFDFDFDFDFDFDFDULL
1639 },
1640 {
1641 0x000000000000FDFDULL,
1642 0x0000000000FDFDFDULL,
1643 0x00000000FDFDFDFDULL,
1644 0x000000FDFDFDFDFDULL,
1645 0x0000FDFDFDFDFDFDULL,
1646 0x00FDFDFDFDFDFDFDULL,
1647 0xFDFDFDFDFDFDFDFDULL,
1648 0xFDFDFDFDFDFDFDFDULL
1649 },
1650 {
1651 0x0000000000FDFDFDULL,
1652 0x00000000FDFDFDFDULL,
1653 0x000000FDFDFDFDFDULL,
1654 0x0000FDFDFDFDFDFDULL,
1655 0x00FDFDFDFDFDFDFDULL,
1656 0xFDFDFDFDFDFDFDFDULL,
1657 0xFDFDFDFDFDFDFDFDULL,
1658 0xFDFDFDFDFDFDFDFDULL
1659 },
1660 {
1661 0x00000000FDFDFDFDULL,
1662 0x000000FDFDFDFDFDULL,
1663 0x0000FDFDFDFDFDFDULL,
1664 0x00FDFDFDFDFDFDFDULL,
1665 0xFDFDFDFDFDFDFDFDULL,
1666 0xFDFDFDFDFDFDFDFDULL,
1667 0xFDFDFDFDFDFDFDFDULL,
1668 0xFDFDFDFDFDFDFDFDULL
1669 },
1670 {
1671 0x000000FDFDFDFDFDULL,
1672 0x0000FDFDFDFDFDFDULL,
1673 0x00FDFDFDFDFDFDFDULL,
1674 0xFDFDFDFDFDFDFDFDULL,
1675 0xFDFDFDFDFDFDFDFDULL,
1676 0xFDFDFDFDFDFDFDFDULL,
1677 0xFDFDFDFDFDFDFDFDULL,
1678 0xFDFDFDFDFDFDFDFDULL
1679 },
1680 {
1681 0x0000FDFDFDFDFDFDULL,
1682 0x00FDFDFDFDFDFDFDULL,
1683 0xFDFDFDFDFDFDFDFDULL,
1684 0xFDFDFDFDFDFDFDFDULL,
1685 0xFDFDFDFDFDFDFDFDULL,
1686 0xFDFDFDFDFDFDFDFDULL,
1687 0xFDFDFDFDFDFDFDFDULL,
1688 0xFDFDFDFDFDFDFDFDULL
1689 },
1690 {
1691 0x00FDFDFDFDFDFDFDULL,
1692 0xFDFDFDFDFDFDFDFDULL,
1693 0xFDFDFDFDFDFDFDFDULL,
1694 0xFDFDFDFDFDFDFDFDULL,
1695 0xFDFDFDFDFDFDFDFDULL,
1696 0xFDFDFDFDFDFDFDFDULL,
1697 0xFDFDFDFDFDFDFDFDULL,
1698 0xFDFDFDFDFDFDFDFDULL
1699 },
1700 {
1701 0xFDFDFDFDFDFDFDFDULL,
1702 0xFDFDFDFDFDFDFDFDULL,
1703 0xFDFDFDFDFDFDFDFDULL,
1704 0xFDFDFDFDFDFDFDFDULL,
1705 0xFDFDFDFDFDFDFDFDULL,
1706 0xFDFDFDFDFDFDFDFDULL,
1707 0xFDFDFDFDFDFDFDFDULL,
1708 0xFDFDFDFDFDFDFDFDULL
1709 }
1710 }
1711 };
1712
1713 int32_t black_opening_count=0;
1714 int32_t black_opening_x,black_opening_y;
1715 int32_t black_opening_shape;
1716
1717 1507 int32_t choose_opening_shape()
1718 {
1719 // First, count how many bits are set
1720 1507 int32_t numBits=0;
1721 int32_t bitCounter;
1722
1723
2/2
✓ Branch 0 taken 7535 times.
✓ Branch 1 taken 1507 times.
9042 for(int32_t i=0; i<bosMAX; i++)
1724 {
1725
2/2
✓ Branch 0 taken 5812 times.
✓ Branch 1 taken 1723 times.
7535 if(COOLSCROLL&(1<<i))
1726 1723 numBits++;
1727 7535 }
1728
1729 // Shouldn't happen...
1730
1/2
✓ Branch 0 taken 1507 times.
✗ Branch 1 not taken.
1507 if(numBits==0)
1731 return bosCIRCLE;
1732
1733 // Pick a bit
1734 1507 bitCounter=zc_rand()%numBits+1;
1735
1736
2/2
✓ Branch 0 taken 1990 times.
✓ Branch 1 taken 26 times.
2016 for(int32_t i=0; i<bosMAX; i++)
1737 {
1738 // If this bit is set, decrement the bit counter
1739
2/2
✓ Branch 0 taken 353 times.
✓ Branch 1 taken 1637 times.
1990 if(COOLSCROLL&(1<<i))
1740 1637 bitCounter--;
1741
1742 // When the counter hits 0, return a value based on
1743 // which bit it stopped on.
1744 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1745
2/2
✓ Branch 0 taken 1481 times.
✓ Branch 1 taken 509 times.
1990 if(bitCounter==0)
1746 1481 return i;
1747 509 }
1748
1749 // Shouldn't be necessary, but the compiler might complain, at least
1750 26 return bosCIRCLE;
1751 1507 }
1752
1753 396 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1754 {
1755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 396 times.
396 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1756
1757 396 int32_t w=256, h=224;
1758 396 int32_t blockrows=28, blockcolumns=32;
1759 396 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1760
1761
2/2
✓ Branch 0 taken 11088 times.
✓ Branch 1 taken 396 times.
11484 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1762 {
1763
2/2
✓ Branch 0 taken 354816 times.
✓ Branch 1 taken 11088 times.
365904 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1764 {
1765
2/2
✓ Branch 0 taken 147229 times.
✓ Branch 1 taken 207587 times.
354816 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1766 354816 }
1767 11088 }
1768
1769 396 black_opening_count = 66;
1770 396 black_opening_x = x;
1771 396 black_opening_y = y;
1772 396 lensclk = 0;
1773 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1774
1775
1776
1/2
✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
396 if(black_opening_shape == bosFADEBLACK)
1777 {
1778 refreshTints();
1779 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1780 }
1781
1/2
✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
396 if(wait)
1782 {
1783 FFCore.warpScriptCheck();
1784 for(int32_t i=0; i<66; i++)
1785 {
1786 draw_screen(tmpscr);
1787 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1788 advanceframe(true);
1789
1790 if(Quit)
1791 {
1792 break;
1793 }
1794 }
1795 }
1796 396 }
1797
1798 1111 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1799 {
1800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1111 times.
1111 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1801
1802 1111 int32_t w=256, h=224;
1803 1111 int32_t blockrows=28, blockcolumns=32;
1804 1111 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1805
1806
2/2
✓ Branch 0 taken 31108 times.
✓ Branch 1 taken 1111 times.
32219 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1807 {
1808
2/2
✓ Branch 0 taken 995456 times.
✓ Branch 1 taken 31108 times.
1026564 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1809 {
1810
2/2
✓ Branch 0 taken 506633 times.
✓ Branch 1 taken 488823 times.
995456 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1811 995456 }
1812 31108 }
1813
1814 1111 black_opening_count = -66;
1815 1111 black_opening_x = x;
1816 1111 black_opening_y = y;
1817 1111 lensclk = 0;
1818
1/2
✓ Branch 0 taken 1111 times.
✗ Branch 1 not taken.
1111 if(black_opening_shape == bosFADEBLACK)
1819 {
1820 refreshTints();
1821 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1822 }
1823
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 912 times.
1111 if(wait)
1824 {
1825 912 FFCore.warpScriptCheck();
1826
2/2
✓ Branch 0 taken 912 times.
✓ Branch 1 taken 60192 times.
61104 for(int32_t i=0; i<66; i++)
1827 {
1828 60192 draw_screen(tmpscr);
1829 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1830 60192 advanceframe(true);
1831
1832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60192 times.
60192 if(Quit)
1833 {
1834 break;
1835 }
1836 60192 }
1837 912 }
1838 1111 }
1839
1840 99462 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1841 {
1842 99462 clear_to_color(tmp_scr,BLACK);
1843 99462 int32_t w=256, h=224;
1844
1845
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 858 times.
✓ Branch 2 taken 594 times.
✓ Branch 3 taken 7656 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 90354 times.
99462 switch(black_opening_shape)
1846 {
1847 case bosOVAL:
1848 {
1849 858 double new_w=(w/2)+abs(w/2-x);
1850 858 double new_h=(h/2)+abs(h/2-y);
1851 858 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1852 858 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1853 858 break;
1854 }
1855
1856 case bosTRIANGLE:
1857 {
1858 594 double new_w=(w/2)+abs(w/2-x);
1859 594 double new_h=(h/2)+abs(h/2-y);
1860 594 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1861 594 double P2= (PI/2);
1862 594 double P23=(2*PI/3);
1863 594 double P43=(4*PI/3);
1864 594 double Pa= (-4*PI*a/(3*max_a));
1865 594 double angle=P2+Pa;
1866 594 double a0=angle;
1867 594 double a2=angle+P23;
1868 594 double a4=angle+P43;
1869 1188 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1870 594 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1871 594 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1872 0);
1873 594 break;
1874 }
1875
1876 case bosSMAS:
1877 {
1878
2/2
✓ Branch 0 taken 4158 times.
✓ Branch 1 taken 3498 times.
7656 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1879
1880
2/2
✓ Branch 0 taken 214368 times.
✓ Branch 1 taken 7656 times.
222024 for(int32_t blockrow=0; blockrow<28; ++blockrow) //30
1881 {
1882
2/2
✓ Branch 0 taken 1714944 times.
✓ Branch 1 taken 214368 times.
1929312 for(int32_t linerow=0; linerow<8; ++linerow)
1883 {
1884 1714944 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1885
1886
2/2
✓ Branch 0 taken 54878208 times.
✓ Branch 1 taken 1714944 times.
56593152 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1887 {
1888 164634624 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1889
6/6
✓ Branch 0 taken 39546648 times.
✓ Branch 1 taken 15331560 times.
✓ Branch 2 taken 35934032 times.
✓ Branch 3 taken 18944176 times.
✓ Branch 4 taken 20602472 times.
✓ Branch 5 taken 15331560 times.
54878208 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1890 54878208 [linerow];
1891 54878208 ++triangleline;
1892
1893
2/2
✓ Branch 0 taken 48018432 times.
✓ Branch 1 taken 6859776 times.
54878208 if(linerow==0)
1894 {
1895 6859776 }
1896 54878208 }
1897 1714944 }
1898 214368 }
1899
1900 7656 break;
1901 }
1902
1903 case bosFADEBLACK:
1904 {
1905 if(black_opening_count<0)
1906 {
1907 black_fade(zc_min(-black_opening_count,63));
1908 }
1909 else if(black_opening_count>0)
1910 {
1911 black_fade(63-zc_max(black_opening_count-3,0));
1912 }
1913 else black_fade(0);
1914 return; //no blitting from tmp_scr!
1915 }
1916
1917 90354 case bosCIRCLE:
1918 default:
1919 {
1920 90354 double new_w=(w/2)+abs(w/2-x);
1921 90354 double new_h=(h/2)+abs(h/2-y);
1922 90354 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1923 //circlefill(tmp_scr,x,y,a<<3,0);
1924 90354 circlefill(tmp_scr,x,y,r,0);
1925 90354 break;
1926 }
1927 }
1928
1929 99462 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1930 99462 }
1931
1932
1933 void black_fade(int32_t fadeamnt)
1934 {
1935 for(int32_t i=0; i < 0xEF; i++)
1936 {
1937 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,63);
1938 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,63);
1939 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,63);
1940 }
1941
1942 refreshpal = true;
1943 }
1944
1945 //----------------------------------------------------------------
1946
1947 44284874 bool item_disabled(int32_t item) //is this item disabled?
1948 {
1949
2/2
✓ Branch 0 taken 1814710 times.
✓ Branch 1 taken 42470164 times.
44284874 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1950 }
1951
1952 7617759 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1953 {
1954
2/2
✓ Branch 0 taken 135210 times.
✓ Branch 1 taken 7482549 times.
7617759 if(current_item(item_type, true) >=item)
1955 {
1956 135210 return true;
1957 }
1958
1959 7482549 return false;
1960 7617759 }
1961
1962 31052790 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1963 {
1964
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 6053114 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3220277 times.
✓ Branch 6 taken 16170214 times.
✓ Branch 7 taken 5493498 times.
✓ Branch 8 taken 115687 times.
31052790 switch(item_type)
1965 {
1966 case itype_bomb:
1967 case itype_sbomb:
1968 {
1969 int32_t itemid = getItemID(itemsbuf, item_type, it);
1970
1971 if(itemid == -1)
1972 return false;
1973
1974 return (game->get_item(itemid));
1975 }
1976
1977 case itype_clock:
1978 {
1979 6053114 int32_t itemid = getItemID(itemsbuf, item_type, it);
1980
1981
2/4
✓ Branch 0 taken 6053114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6053114 times.
✗ Branch 3 not taken.
6053114 if(itemid != -1 && (itemsbuf[itemid].flags & ITEM_FLAG1)) //Active clock
1982 return (game->get_item(itemid));
1983 6053114 return Hero.getClock()?1:0;
1984 }
1985
1986 case itype_key:
1987 return (game->get_keys()>0);
1988
1989 case itype_magiccontainer:
1990 return (game->get_maxmagic()>=game->get_mp_per_block());
1991
1992 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1993 {
1994
1/3
✓ Branch 0 taken 3220277 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
3220277 switch(it)
1995 {
1996 case -2:
1997 {
1998 for(int32_t i=0; i<MAXLEVELS; i++)
1999 {
2000 if(game->lvlitems[i]&liTRIFORCE)
2001 {
2002 return true;
2003 }
2004 }
2005
2006 return false;
2007 }
2008
2009 case -1:
2010 return (game->lvlitems[dlevel]&liTRIFORCE);
2011
2012 default:
2013
2/4
✓ Branch 0 taken 3220277 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3220277 times.
3220277 if(it>=0&&it<MAXLEVELS)
2014 {
2015 3220277 return (game->lvlitems[it]&liTRIFORCE);
2016 }
2017
2018 break;
2019 }
2020
2021 return 0;
2022 }
2023
2024 case itype_map: //it: -2=any, -1=current level, other=that level
2025 {
2026
1/3
✓ Branch 0 taken 16170214 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
16170214 switch(it)
2027 {
2028 case -2:
2029 {
2030 for(int32_t i=0; i<MAXLEVELS; i++)
2031 {
2032 if(game->lvlitems[i]&liMAP)
2033 {
2034 return true;
2035 }
2036 }
2037
2038 return false;
2039 }
2040
2041 case -1:
2042 return (game->lvlitems[dlevel]&liMAP)!=0;
2043
2044 default:
2045
2/4
✓ Branch 0 taken 16170214 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16170214 times.
16170214 if(it>=0&&it<MAXLEVELS)
2046 {
2047 16170214 return (game->lvlitems[it]&liMAP)!=0;
2048 }
2049
2050 break;
2051 }
2052
2053 return 0;
2054 }
2055
2056 case itype_compass: //it: -2=any, -1=current level, other=that level
2057 {
2058
1/3
✓ Branch 0 taken 5493498 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
5493498 switch(it)
2059 {
2060 case -2:
2061 {
2062 for(int32_t i=0; i<MAXLEVELS; i++)
2063 {
2064 if(game->lvlitems[i]&liCOMPASS)
2065 {
2066 return true;
2067 }
2068 }
2069
2070 return false;
2071 }
2072
2073 case -1:
2074 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
2075
2076 default:
2077
2/4
✓ Branch 0 taken 5493498 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5493498 times.
✗ Branch 3 not taken.
5493498 if(it>=0&&it<MAXLEVELS)
2078 {
2079 5493498 return (game->lvlitems[it]&liCOMPASS)!=0;
2080 }
2081
2082 break;
2083 }
2084 return 0;
2085 }
2086
2087 case itype_bosskey: //it: -2=any, -1=current level, other=that level
2088 {
2089
1/3
✓ Branch 0 taken 115687 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
115687 switch(it)
2090 {
2091 case -2:
2092 {
2093 for(int32_t i=0; i<MAXLEVELS; i++)
2094 {
2095 if(game->lvlitems[i]&liBOSSKEY)
2096 {
2097 return true;
2098 }
2099 }
2100
2101 return false;
2102 }
2103
2104 case -1:
2105 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
2106
2107 default:
2108
2/4
✓ Branch 0 taken 115687 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 115687 times.
115687 if(it>=0&&it<MAXLEVELS)
2109 {
2110 115687 return (game->lvlitems[it]&liBOSSKEY)?1:0;
2111 }
2112 break;
2113 }
2114 return 0;
2115 }
2116
2117 default:
2118 //it=(1<<(it-1));
2119 /*if (item_type>=itype_max)
2120 {
2121 enter_sys_pal();
2122 jwin_alert("Error","has_item exception",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2123 exit_sys_pal();
2124
2125 return false;
2126 }*/
2127 int32_t itemid = getItemID(itemsbuf, item_type, it);
2128
2129 if(itemid == -1)
2130 return false;
2131
2132 return game->get_item(itemid);
2133 }
2134 31052790 }
2135
2136
2137 100011162 int32_t current_item(int32_t item_type, bool checkenabled) //item currently being used
2138 {
2139
9/9
✓ Branch 0 taken 6053114 times.
✓ Branch 1 taken 51586250 times.
✓ Branch 2 taken 6053114 times.
✓ Branch 3 taken 6053114 times.
✓ Branch 4 taken 6053114 times.
✓ Branch 5 taken 6053114 times.
✓ Branch 6 taken 6053114 times.
✓ Branch 7 taken 6053114 times.
✓ Branch 8 taken 6053114 times.
100011162 switch(item_type)
2140 {
2141 case itype_clock:
2142 {
2143 6053114 int32_t maxid = getHighestLevelOfFamily(game, itemsbuf, item_type, checkenabled);
2144
2145
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6053114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6053114 if(maxid != -1 && (itemsbuf[maxid].flags & ITEM_FLAG1)) //Active clock
2146 return itemsbuf[maxid].fam_type;
2147
2148 6053114 return has_item(itype_clock,1) ? 1 : 0;
2149 }
2150
2151 case itype_key:
2152 6053114 return game->get_keys();
2153
2154 case itype_lkey:
2155 6053114 return game->lvlkeys[get_dlevel()];
2156
2157 case itype_magiccontainer:
2158 6053114 return game->get_maxmagic()/game->get_mp_per_block();
2159
2160 case itype_triforcepiece:
2161 {
2162 6053114 int32_t count=0;
2163
2164
2/2
✓ Branch 0 taken 3099194368 times.
✓ Branch 1 taken 6053114 times.
3105247482 for(int32_t i=0; i<MAXLEVELS; i++)
2165 {
2166 3099194368 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
2167 3099194368 }
2168
2169 6053114 return count;
2170 }
2171
2172 case itype_map:
2173 {
2174 6053114 int32_t count=0;
2175
2176
2/2
✓ Branch 0 taken 3099194368 times.
✓ Branch 1 taken 6053114 times.
3105247482 for(int32_t i=0; i<MAXLEVELS; i++)
2177 {
2178 3099194368 count+=(game->lvlitems[i]&liMAP)?1:0;
2179 3099194368 }
2180
2181 6053114 return count;
2182 }
2183
2184 case itype_compass:
2185 {
2186 6053114 int32_t count=0;
2187
2188
2/2
✓ Branch 0 taken 3099194368 times.
✓ Branch 1 taken 6053114 times.
3105247482 for(int32_t i=0; i<MAXLEVELS; i++)
2189 {
2190 3099194368 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
2191 3099194368 }
2192
2193 6053114 return count;
2194 }
2195
2196 case itype_bosskey:
2197 {
2198 6053114 int32_t count=0;
2199
2200
2/2
✓ Branch 0 taken 3099194368 times.
✓ Branch 1 taken 6053114 times.
3105247482 for(int32_t i=0; i<MAXLEVELS; i++)
2201 {
2202 3099194368 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2203 3099194368 }
2204
2205 6053114 return count;
2206 }
2207
2208 default:
2209 51586250 int32_t maxid = getHighestLevelOfFamily(game, itemsbuf, item_type, checkenabled);
2210
2211
2/2
✓ Branch 0 taken 9872037 times.
✓ Branch 1 taken 41714213 times.
51586250 if(maxid == -1)
2212 41714213 return 0;
2213
2214 9872037 return itemsbuf[maxid].fam_type;
2215 }
2216 100011162 }
2217
2218 92393403 int32_t current_item(int32_t item_type) //item currently being used
2219 {
2220 92393403 return current_item(item_type, true);
2221 }
2222
2223 116 std::map<int32_t, int32_t> itemcache;
2224 116 std::map<int32_t, int32_t> itemcache_cost;
2225
2226 void removeFromItemCache(int32_t itemclass)
2227 {
2228 itemcache.erase(itemclass);
2229 itemcache_cost.erase(itemclass);
2230 }
2231
2232 5860243 void flushItemCache(bool justcost)
2233 {
2234 5860243 itemcache_cost.clear();
2235
2/2
✓ Branch 0 taken 5830315 times.
✓ Branch 1 taken 29928 times.
5860243 if(!justcost)
2236 29928 itemcache.clear();
2237
2/2
✓ Branch 0 taken 5829883 times.
✓ Branch 1 taken 432 times.
5830315 else if(replay_version_check(0,19))
2238 5829883 return;
2239
2240 //also fix the active subscreen if items were deleted -DD
2241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30360 times.
30360 if(game != NULL)
2242 {
2243 30360 verifyBothWeapons();
2244 30360 refresh_subscr_items();
2245 30360 }
2246 5860243 }
2247
2248 // This is used often, so it should be as direct as possible.
2249 3368757576 int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2250 {
2251 3368757576 bool use_cost_cache = replay_version_check(19);
2252
2/2
✓ Branch 0 taken 3293277091 times.
✓ Branch 1 taken 75480485 times.
3368757576 if(jinx_check)
2253 {
2254
4/4
✓ Branch 0 taken 47335562 times.
✓ Branch 1 taken 28144923 times.
✓ Branch 2 taken 8256298 times.
✓ Branch 3 taken 39079264 times.
75480485 if(!(HeroSwordClk() || HeroItemClk()))
2255 39079264 jinx_check = false; //not jinxed
2256 75480485 }
2257
2/2
✓ Branch 0 taken 1045644 times.
✓ Branch 1 taken 3367711932 times.
3368757576 if(!Hero.BunnyClock())
2258 3367711932 check_bunny = false; //not bunnied
2259
2/2
✓ Branch 0 taken 3339144972 times.
✓ Branch 1 taken 29612604 times.
3368757576 if(itemtype == itype_ring) checkmagic = true;
2260
4/4
✓ Branch 0 taken 3332356355 times.
✓ Branch 1 taken 36401221 times.
✓ Branch 2 taken 3300694652 times.
✓ Branch 3 taken 29260980 times.
6698713208 if (!jinx_check && !check_bunny
2261
3/4
✓ Branch 0 taken 3332356355 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3329955632 times.
✓ Branch 3 taken 2400723 times.
3332356355 && (use_cost_cache || itemtype != itype_ring))
2262 {
2263
4/4
✓ Branch 0 taken 178066534 times.
✓ Branch 1 taken 3125028841 times.
✓ Branch 2 taken 177852940 times.
✓ Branch 3 taken 213594 times.
3303095375 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2264 3303095375 auto res = cache.find(itemtype);
2265
2266
2/2
✓ Branch 0 taken 3287821280 times.
✓ Branch 1 taken 15274095 times.
3303095375 if(res != cache.end())
2267 3287821280 return res->second;
2268 15274095 }
2269
2270 80936296 int32_t result = -1;
2271 80936296 int32_t highestlevel = -1;
2272
2273
2/2
✓ Branch 0 taken 20719691776 times.
✓ Branch 1 taken 80936296 times.
20800628072 for(int32_t i=0; i<MAXITEMS; i++)
2274 {
2275
5/6
✓ Branch 0 taken 1519117245 times.
✓ Branch 1 taken 19200574531 times.
✓ Branch 2 taken 21704762 times.
✓ Branch 3 taken 1497412483 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 21704762 times.
20719691776 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2276 {
2277
4/4
✓ Branch 0 taken 19863315 times.
✓ Branch 1 taken 1841447 times.
✓ Branch 2 taken 8694 times.
✓ Branch 3 taken 19854621 times.
21704762 if(checkmagic && itemtype != itype_magicring)
2278
2/2
✓ Branch 0 taken 19854451 times.
✓ Branch 1 taken 170 times.
19854621 if(!checkmagiccost(i))
2279 170 continue;
2280
6/6
✓ Branch 0 taken 18586575 times.
✓ Branch 1 taken 3118017 times.
✓ Branch 2 taken 243036 times.
✓ Branch 3 taken 2874981 times.
✓ Branch 4 taken 1737351 times.
✓ Branch 5 taken 1380666 times.
21704592 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380666 times.
1380666 if(!(itemsbuf[i].flags & ITEM_JINX_IMMUNE))
2282 1380666 continue;
2283
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 20323926 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
20323926 if(check_bunny && !checkbunny(i))
2284 continue;
2285
2286
2/2
✓ Branch 0 taken 231013 times.
✓ Branch 1 taken 20092913 times.
20323926 if(itemsbuf[i].fam_type >= highestlevel)
2287 {
2288 20092913 highestlevel = itemsbuf[i].fam_type;
2289 20092913 result=i;
2290 20092913 }
2291 20323926 }
2292 20718310940 }
2293
2294
3/4
✓ Branch 0 taken 44535075 times.
✓ Branch 1 taken 36401221 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 44535075 times.
80936296 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2295 {
2296
2/2
✓ Branch 0 taken 5772 times.
✓ Branch 1 taken 44529303 times.
44535075 if (use_cost_cache)
2297 {
2298
2/2
✓ Branch 0 taken 3612 times.
✓ Branch 1 taken 2160 times.
5772 if (!checkmagic)
2299 2160 itemcache[itemtype] = result;
2300
5/6
✓ Branch 0 taken 2160 times.
✓ Branch 1 taken 3612 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2156 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
5772 if (checkmagic || result < 0 || checkmagiccost(result))
2301 5772 itemcache_cost[itemtype] = result;
2302 5772 }
2303 else
2304 {
2305 44529303 itemcache[itemtype] = result;
2306 }
2307 44535075 }
2308 80936296 return result;
2309 3368757576 }
2310
2311 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2312 3332800568 int32_t current_item_id(int32_t itype, bool checkmagic, bool jinx_check, bool check_bunny)
2313 {
2314
2/4
✓ Branch 0 taken 3332800568 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3332800568 times.
3332800568 if(itype < 0 || itype >= itype_max) return -1;
2315
1/2
✓ Branch 0 taken 3332800568 times.
✗ Branch 1 not taken.
3332800568 if(game->OverrideItems[itype] > -2)
2316 {
2317 auto ovid = game->OverrideItems[itype];
2318 if(ovid < 0 || ovid >= MAXITEMS)
2319 return -1;
2320 if(itemsbuf[ovid].family == itype)
2321 {
2322 if(itype == itype_magicring)
2323 checkmagic = false;
2324 else if(itype == itype_ring)
2325 checkmagic = true;
2326
2327 if(checkmagic && !checkmagiccost(ovid))
2328 return -1;
2329 if(jinx_check && !(itemsbuf[ovid].flags & ITEM_JINX_IMMUNE)
2330 && (usesSwordJinx(ovid) ? HeroSwordClk() : HeroItemClk()))
2331 return -1;
2332 return ovid;
2333 }
2334 }
2335 3332800568 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2336
2/2
✓ Branch 0 taken 39523477 times.
✓ Branch 1 taken 3293277091 times.
3332800568 if(!jinx_check) //If not already a jinx-immune-only check...
2337 {
2338 //And the player IS jinxed...
2339
4/4
✓ Branch 0 taken 3265475145 times.
✓ Branch 1 taken 27801946 times.
✓ Branch 2 taken 8155062 times.
✓ Branch 3 taken 3257320083 times.
3293277091 if(HeroSwordClk() || HeroItemClk())
2340 {
2341 //Then do a jinx-immune-only check here
2342 35957008 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2343 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2344 //Should NOT need a compat rule, as this should always return -1 in old quests.
2345
2/2
✓ Branch 0 taken 1208256 times.
✓ Branch 1 taken 34748752 times.
35957008 if(ret2 > -1) return ret2;
2346 34748752 }
2347 3292068835 }
2348 3331592312 return ret;
2349 3332800568 }
2350
2351 19337695 int32_t current_item_power(int32_t itemtype)
2352 {
2353 19337695 int32_t result = current_item_id(itemtype,true);
2354
2/2
✓ Branch 0 taken 14044987 times.
✓ Branch 1 taken 5292708 times.
19337695 return (result<0) ? 0 : itemsbuf[result].power;
2355 }
2356
2357 11 int32_t heart_container_id()
2358 {
2359
1/2
✓ Branch 0 taken 319 times.
✗ Branch 1 not taken.
319 for(int32_t i=0; i<MAXITEMS; i++)
2360 {
2361
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 308 times.
319 if(itemsbuf[i].family == itype_heartcontainer)
2362 {
2363 11 return i;
2364 }
2365 308 }
2366 return -1;
2367 11 }
2368
2369 6053114 int32_t item_tile_mod()
2370 {
2371 6053114 int32_t tile=0;
2372
2373
2/2
✓ Branch 0 taken 1206889 times.
✓ Branch 1 taken 4846225 times.
6053114 if(game->get_bombs())
2374 {
2375 4846225 int32_t itemid = current_item_id(itype_bomb,false);
2376
3/4
✓ Branch 0 taken 4681056 times.
✓ Branch 1 taken 165169 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4681056 times.
4846225 if(itemid > -1 && checkbunny(itemid))
2377 4681056 tile+=itemsbuf[itemid].ltm;
2378 4846225 }
2379
2380
2/2
✓ Branch 0 taken 4539824 times.
✓ Branch 1 taken 1513290 times.
6053114 if(game->get_sbombs())
2381 {
2382 1513290 int32_t itemid = current_item_id(itype_sbomb,false);
2383
3/4
✓ Branch 0 taken 1511862 times.
✓ Branch 1 taken 1428 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1511862 times.
1513290 if(itemid > -1 && checkbunny(itemid))
2384 1511862 tile+=itemsbuf[itemid].ltm;
2385 1513290 }
2386
2387
2/2
✓ Branch 0 taken 5943414 times.
✓ Branch 1 taken 109700 times.
6053114 if(current_item(itype_clock))
2388 {
2389 109700 int32_t itemid =
2390
1/2
✓ Branch 0 taken 109700 times.
✗ Branch 1 not taken.
109700 get_qr(qr_HARDCODED_LITEM_LTMS)
2391 ? iClock
2392 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2393
2/4
✓ Branch 0 taken 109700 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 109700 times.
109700 if(itemid > -1 && checkbunny(itemid))
2394 109700 tile+=itemsbuf[itemid].ltm;
2395 109700 }
2396
2397
2/2
✓ Branch 0 taken 4672373 times.
✓ Branch 1 taken 1380741 times.
6053114 if(current_item(itype_key))
2398 {
2399 1380741 int32_t itemid =
2400
1/2
✓ Branch 0 taken 1380741 times.
✗ Branch 1 not taken.
1380741 get_qr(qr_HARDCODED_LITEM_LTMS)
2401 ? iKey
2402 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2403
2/4
✓ Branch 0 taken 1380741 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1380741 times.
1380741 if(itemid > -1 && checkbunny(itemid))
2404 1380741 tile+=itemsbuf[itemid].ltm;
2405 1380741 }
2406
2407
2/2
✓ Branch 0 taken 5786011 times.
✓ Branch 1 taken 267103 times.
6053114 if(current_item(itype_lkey))
2408 {
2409 267103 int32_t itemid =
2410
2/2
✓ Branch 0 taken 266193 times.
✓ Branch 1 taken 910 times.
267103 get_qr(qr_HARDCODED_LITEM_LTMS)
2411 ? iLevelKey
2412 910 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2413
2/4
✓ Branch 0 taken 267103 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 267103 times.
267103 if(itemid > -1 && checkbunny(itemid))
2414 267103 tile+=itemsbuf[itemid].ltm;
2415 267103 }
2416
2417
2/2
✓ Branch 0 taken 1257083 times.
✓ Branch 1 taken 4796031 times.
6053114 if(current_item(itype_map))
2418 {
2419 4796031 int32_t itemid =
2420
1/2
✓ Branch 0 taken 4796031 times.
✗ Branch 1 not taken.
4796031 get_qr(qr_HARDCODED_LITEM_LTMS)
2421 ? iMap
2422 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2423
2/4
✓ Branch 0 taken 4796031 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4796031 times.
4796031 if(itemid > -1 && checkbunny(itemid))
2424 4796031 tile+=itemsbuf[itemid].ltm;
2425 4796031 }
2426
2427
2/2
✓ Branch 0 taken 1234415 times.
✓ Branch 1 taken 4818699 times.
6053114 if(current_item(itype_compass))
2428 {
2429 4818699 int32_t itemid =
2430
2/2
✓ Branch 0 taken 4737640 times.
✓ Branch 1 taken 81059 times.
4818699 get_qr(qr_HARDCODED_LITEM_LTMS)
2431 ? iCompass
2432 81059 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2433
2/4
✓ Branch 0 taken 4818699 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4818699 times.
4818699 if(itemid > -1 && checkbunny(itemid))
2434 4818699 tile+=itemsbuf[itemid].ltm;
2435 4818699 }
2436
2437
2/2
✓ Branch 0 taken 3422569 times.
✓ Branch 1 taken 2630545 times.
6053114 if(current_item(itype_bosskey))
2438 {
2439 2630545 int32_t itemid =
2440
1/2
✓ Branch 0 taken 2630545 times.
✗ Branch 1 not taken.
2630545 get_qr(qr_HARDCODED_LITEM_LTMS)
2441 ? iBossKey
2442 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2443
2/4
✓ Branch 0 taken 2630545 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2630545 times.
2630545 if(itemid > -1 && checkbunny(itemid))
2444 2630545 tile+=itemsbuf[itemid].ltm;
2445 2630545 }
2446
2447
2/2
✓ Branch 0 taken 2919924 times.
✓ Branch 1 taken 3133190 times.
6053114 if(current_item(itype_magiccontainer))
2448 {
2449 3133190 int32_t itemid =
2450
2/2
✓ Branch 0 taken 3040989 times.
✓ Branch 1 taken 92201 times.
3133190 get_qr(qr_HARDCODED_LITEM_LTMS)
2451 ? iMagicC
2452 92201 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2453
3/4
✓ Branch 0 taken 3133190 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1870 times.
✓ Branch 3 taken 3131320 times.
3133190 if(itemid > -1 && checkbunny(itemid))
2454 3131320 tile+=itemsbuf[itemid].ltm;
2455 3133190 }
2456
2457
2/2
✓ Branch 0 taken 1592480 times.
✓ Branch 1 taken 4460634 times.
6053114 if(current_item(itype_triforcepiece))
2458 {
2459 4460634 int32_t itemid =
2460
1/2
✓ Branch 0 taken 4460634 times.
✗ Branch 1 not taken.
4460634 get_qr(qr_HARDCODED_LITEM_LTMS)
2461 ? iTriforce
2462 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2463
2/4
✓ Branch 0 taken 4460634 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4460634 times.
4460634 if(itemid > -1 && checkbunny(itemid))
2464 4460634 tile+=itemsbuf[itemid].ltm;
2465 4460634 }
2466
2467
2/2
✓ Branch 0 taken 6053114 times.
✓ Branch 1 taken 3099194368 times.
3105247482 for(int32_t i=0; i<itype_max; i++)
2468 {
2469
2/2
✓ Branch 0 taken 3042451456 times.
✓ Branch 1 taken 56742912 times.
3099194368 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2470 {
2471
2/2
✓ Branch 0 taken 1108260 times.
✓ Branch 1 taken 55634652 times.
56742912 switch(i)
2472 {
2473 case itype_bomb:
2474 case itype_sbomb:
2475 case itype_clock:
2476 case itype_key:
2477 case itype_lkey:
2478 case itype_map:
2479 case itype_compass:
2480 case itype_bosskey:
2481 case itype_magiccontainer:
2482 case itype_triforcepiece:
2483 1108260 continue; //already handled
2484 }
2485 55634652 }
2486 3098086108 int32_t itemid = current_item_id(i,false);
2487
2/2
✓ Branch 0 taken 3092032994 times.
✓ Branch 1 taken 6053114 times.
3098086108 if(i == itype_shield)
2488 6053114 itemid = getCurrentShield(false);
2489
2490
4/4
✓ Branch 0 taken 80828981 times.
✓ Branch 1 taken 3017257127 times.
✓ Branch 2 taken 100981 times.
✓ Branch 3 taken 80728000 times.
3098086108 if(itemid < 0 || !checkbunny(itemid))
2491 3017358108 continue;
2492
2493 80728000 itemdata const& itm = itemsbuf[itemid];
2494
2495
2/2
✓ Branch 0 taken 75312220 times.
✓ Branch 1 taken 5415780 times.
80728000 switch(itm.family)
2496 {
2497 case itype_shield:
2498
1/2
✓ Branch 0 taken 5415780 times.
✗ Branch 1 not taken.
5415780 if(itm.flags & ITEM_FLAG9) //active shield
2499 {
2500 if(!usingActiveShield(itemid))
2501 {
2502 tile+=itm.misc6; //'Inactive PTM'
2503 continue;
2504 }
2505 }
2506 5415780 break;
2507 }
2508
2509 80728000 tile+=itm.ltm;
2510 80728000 }
2511
2512 6053114 return tile;
2513 }
2514
2515 6053114 int32_t bunny_tile_mod()
2516 {
2517
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 6051244 times.
6053114 if(Hero.BunnyClock())
2518 {
2519 1870 return game->get_bunny_ltm();
2520 }
2521 6051244 return 0;
2522 6053114 }
2523
2524 // Hints are drawn on a separate layer to combo reveals.
2525 16332 void draw_lens_under(BITMAP *dest, bool layer)
2526 {
2527 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2528 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2529 //Lens flag 3: Don't show armos/chest/dive items
2530 //Lens flag 4: Show Raft Paths
2531 //Lens flag 5: Show Invisible Enemies
2532
4/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 15876 times.
✓ Branch 2 taken 7938 times.
✓ Branch 3 taken 7938 times.
16332 bool hints = (itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG1));
2533
2534 16332 int32_t strike_hint_table[11]=
2535 {
2536 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2537 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2538 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2539 };
2540
2541 // int32_t page = tmpscr->cpage;
2542 {
2543 16332 int32_t blink_rate=flash_reduction_enabled()?6:1;
2544 // int32_t temptimer=0;
2545 16332 int32_t tempitem, tempweapon=0;
2546 16332 strike_hint=strike_hint_table[strike_hint_counter];
2547
2548
2/2
✓ Branch 0 taken 15842 times.
✓ Branch 1 taken 490 times.
16332 if(strike_hint_timer>32)
2549 {
2550 490 strike_hint_timer=0;
2551 490 strike_hint_counter=((strike_hint_counter+1)%11);
2552 490 }
2553
2554 16332 ++strike_hint_timer;
2555
2556
2/2
✓ Branch 0 taken 2874432 times.
✓ Branch 1 taken 16332 times.
2890764 for(int32_t i=0; i<176; i++)
2557 {
2558 2874432 int32_t x = (i & 15) << 4;
2559 2874432 int32_t y = (i & 0xF0) + playing_field_offset;
2560 2874432 int32_t tempitemx=-16, tempitemy=-16;
2561 2874432 int32_t tempweaponx=-16, tempweapony=-16;
2562
2563
2/2
✓ Branch 0 taken 5748864 times.
✓ Branch 1 taken 2874432 times.
8623296 for(int32_t iter=0; iter<2; ++iter)
2564 {
2565 5748864 int32_t checkflag=0;
2566
2567
2/2
✓ Branch 0 taken 2874432 times.
✓ Branch 1 taken 2874432 times.
5748864 if(iter==0)
2568 {
2569 2874432 checkflag=combobuf[tmpscr->data[i]].flag;
2570 2874432 }
2571 else
2572 {
2573 2874432 checkflag=tmpscr->sflag[i];
2574 }
2575
2576
2/2
✓ Branch 0 taken 5747766 times.
✓ Branch 1 taken 1098 times.
5748864 if(checkflag==mfSTRIKE)
2577 {
2578
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2579 {
2580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSTRIKE],tmpscr->secretcset[sSTRIKE]);
2581 906 }
2582 else
2583 {
2584 192 checkflag = strike_hint;
2585 }
2586 1098 }
2587
2588
20/36
✓ Branch 0 taken 5706470 times.
✓ Branch 1 taken 3148 times.
✓ Branch 2 taken 3618 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2064 times.
✓ Branch 5 taken 28640 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 33 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 5 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
5748864 switch(checkflag)
2589 {
2590 case 0:
2591 case mfZELDA:
2592 case mfPUSHED:
2593 case mfENEMY0:
2594 case mfENEMY1:
2595 case mfENEMY2:
2596 case mfENEMY3:
2597 case mfENEMY4:
2598 case mfENEMY5:
2599 case mfENEMY6:
2600 case mfENEMY7:
2601 case mfENEMY8:
2602 case mfENEMY9:
2603 case mfSINGLE:
2604 case mfSINGLE16:
2605 case mfNOENEMY:
2606 case mfTRAP_H:
2607 case mfTRAP_V:
2608 case mfTRAP_4:
2609 case mfTRAP_LR:
2610 case mfTRAP_UD:
2611 case mfNOGROUNDENEMY:
2612 case mfNOBLOCKS:
2613 case mfSCRIPT1:
2614 case mfSCRIPT2:
2615 case mfSCRIPT3:
2616 case mfSCRIPT4:
2617 case mfSCRIPT5:
2618 case mfSCRIPT6:
2619 case mfSCRIPT7:
2620 case mfSCRIPT8:
2621 case mfSCRIPT9:
2622 case mfSCRIPT10:
2623 case mfSCRIPT11:
2624 case mfSCRIPT12:
2625 case mfSCRIPT13:
2626 case mfSCRIPT14:
2627 case mfSCRIPT15:
2628 case mfSCRIPT16:
2629 case mfSCRIPT17:
2630 case mfSCRIPT18:
2631 case mfSCRIPT19:
2632 case mfSCRIPT20:
2633 case mfPITHOLE:
2634 case mfPITFALLFLOOR:
2635 case mfLAVA:
2636 case mfICE:
2637 case mfICEDAMAGE:
2638 case mfDAMAGE1:
2639 case mfDAMAGE2:
2640 case mfDAMAGE4:
2641 case mfDAMAGE8:
2642 case mfDAMAGE16:
2643 case mfDAMAGE32:
2644 case mfFREEZEALL:
2645 case mfFREZEALLANSFFCS:
2646 case mfFREEZEFFCSOLY:
2647 case mfSCRITPTW1TRIG:
2648 case mfSCRITPTW2TRIG:
2649 case mfSCRITPTW3TRIG:
2650 case mfSCRITPTW4TRIG:
2651 case mfSCRITPTW5TRIG:
2652 case mfSCRITPTW6TRIG:
2653 case mfSCRITPTW7TRIG:
2654 case mfSCRITPTW8TRIG:
2655 case mfSCRITPTW9TRIG:
2656 case mfSCRITPTW10TRIG:
2657 case mfTROWEL:
2658 case mfTROWELNEXT:
2659 case mfTROWELSPECIALITEM:
2660 case mfSLASHPOT:
2661 case mfLIFTPOT:
2662 case mfLIFTORSLASH:
2663 case mfLIFTROCK:
2664 case mfLIFTROCKHEAVY:
2665 case mfDROPITEM:
2666 case mfSPECIALITEM:
2667 case mfDROPKEY:
2668 case mfDROPLKEY:
2669 case mfDROPCOMPASS:
2670 case mfDROPMAP:
2671 case mfDROPBOSSKEY:
2672 case mfSPAWNNPC:
2673 case mfSWITCHHOOK:
2674 case mfSIDEVIEWLADDER:
2675 case mfSIDEVIEWPLATFORM:
2676 case mfNOENEMYSPAWN:
2677 case mfENEMYALL:
2678 case mfNOMIRROR:
2679 case mfUNSAFEGROUND:
2680 case mf168:
2681 case mf169:
2682 case mf170:
2683 case mf171:
2684 case mf172:
2685 case mf173:
2686 case mf174:
2687 case mf175:
2688 case mf176:
2689 case mf177:
2690 case mf178:
2691 case mf179:
2692 case mf180:
2693 case mf181:
2694 case mf182:
2695 case mf183:
2696 case mf184:
2697 case mf185:
2698 case mf186:
2699 case mf187:
2700 case mf188:
2701 case mf189:
2702 case mf190:
2703 case mf191:
2704 case mf192:
2705 case mf193:
2706 case mf194:
2707 case mf195:
2708 case mf196:
2709 case mf197:
2710 case mf198:
2711 case mf199:
2712 case mf200:
2713 case mf201:
2714 case mf202:
2715 case mf203:
2716 case mf204:
2717 case mf205:
2718 case mf206:
2719 case mf207:
2720 case mf208:
2721 case mf209:
2722 case mf210:
2723 case mf211:
2724 case mf212:
2725 case mf213:
2726 case mf214:
2727 case mf215:
2728 case mf216:
2729 case mf217:
2730 case mf218:
2731 case mf219:
2732 case mf220:
2733 case mf221:
2734 case mf222:
2735 case mf223:
2736 case mf224:
2737 case mf225:
2738 case mf226:
2739 case mf227:
2740 case mf228:
2741 case mf229:
2742 case mf230:
2743 case mf231:
2744 case mf232:
2745 case mf233:
2746 case mf234:
2747 case mf235:
2748 case mf236:
2749 case mf237:
2750 case mf238:
2751 case mf239:
2752 case mf240:
2753 case mf241:
2754 case mf242:
2755 case mf243:
2756 case mf244:
2757 case mf245:
2758 case mf246:
2759 case mf247:
2760 case mf248:
2761 case mf249:
2762 case mf250:
2763 case mf251:
2764 case mf252:
2765 case mf253:
2766 case mf254:
2767 case mfEXTENDED:
2768 5706470 break;
2769
2770 case mfPUSHUD:
2771 case mfPUSHLR:
2772 case mfPUSH4:
2773 case mfPUSHU:
2774 case mfPUSHD:
2775 case mfPUSHL:
2776 case mfPUSHR:
2777 case mfPUSHUDNS:
2778 case mfPUSHLRNS:
2779 case mfPUSH4NS:
2780 case mfPUSHUNS:
2781 case mfPUSHDNS:
2782 case mfPUSHLNS:
2783 case mfPUSHRNS:
2784 case mfPUSHUDINS:
2785 case mfPUSHLRINS:
2786 case mfPUSH4INS:
2787 case mfPUSHUINS:
2788 case mfPUSHDINS:
2789 case mfPUSHLINS:
2790 case mfPUSHRINS:
2791
3/4
✓ Branch 0 taken 1829 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1829 times.
3148 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2792
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1829 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1829 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1829 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2793 {
2794 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->undercombo,tmpscr->undercset);
2795 }
2796
2797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3148 times.
3148 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2798
3/6
✓ Branch 0 taken 2438 times.
✓ Branch 1 taken 710 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 710 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3148 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2799 {
2800
2/2
✓ Branch 0 taken 1406 times.
✓ Branch 1 taken 1032 times.
2438 if(hints)
2801 {
2802
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch(combobuf[tmpscr->data[i]].type)
2803 {
2804 case cPUSH_HEAVY:
2805 case cPUSH_HW:
2806 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2807 72 tempitemx=x, tempitemy=y;
2808
2809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(tempitem>-1)
2810 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2811
2812 72 break;
2813
2814 case cPUSH_HEAVY2:
2815 case cPUSH_HW2:
2816 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2817 63 tempitemx=x, tempitemy=y;
2818
2819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
63 if(tempitem>-1)
2820 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2821
2822 63 break;
2823 }
2824 1032 }
2825 2438 }
2826
2827 3148 break;
2828
2829 case mfWHISTLE:
2830
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2831 {
2832 tempitem=getItemID(itemsbuf,itype_whistle,1);
2833
2834 if(tempitem<0) break;
2835
2836 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2837 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2838 {
2839 tempitemx=x;
2840 tempitemy=y;
2841 }
2842
2843 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2844 }
2845
2846 2418 break;
2847
2848 //Why is this here?
2849 case mfFAIRY:
2850 case mfMAGICFAIRY:
2851 case mfALLFAIRY:
2852 if(hints)
2853 {
2854 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2855
2856 if(tempitem < 0) break;
2857
2858 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2859 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2860 {
2861 tempitemx=x;
2862 tempitemy=y;
2863 }
2864
2865 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2866 }
2867
2868 break;
2869
2870 case mfANYFIRE:
2871
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2872 {
2873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBCANDLE],tmpscr->secretcset[sBCANDLE]);
2874 252 }
2875 else
2876 {
2877 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2878
2879
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2880
2881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2882
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2883 {
2884 189 tempitemx=x;
2885 189 tempitemy=y;
2886 189 }
2887
2888 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2889 }
2890
2891 504 break;
2892
2893 case mfSTRONGFIRE:
2894 if(!hints)
2895 {
2896 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sRCANDLE],tmpscr->secretcset[sRCANDLE]);
2897 }
2898 else
2899 {
2900 tempitem=getItemID(itemsbuf,itype_candle,2);
2901
2902 if(tempitem<0) break;
2903
2904 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2905 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2906 {
2907 tempitemx=x;
2908 tempitemy=y;
2909 }
2910
2911 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2912 }
2913
2914 break;
2915
2916 case mfMAGICFIRE:
2917 if(!hints)
2918 {
2919 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDFIRE],tmpscr->secretcset[sWANDFIRE]);
2920 }
2921 else
2922 {
2923 tempitem=getItemID(itemsbuf,itype_wand,1);
2924
2925 if(tempitem<0) break;
2926
2927 tempweapon=wFire;
2928
2929 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2930 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2931 {
2932 tempitemx=x;
2933 tempitemy=y;
2934 }
2935 else
2936 {
2937 tempweaponx=x;
2938 tempweapony=y;
2939 }
2940
2941 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2942 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2943 }
2944
2945 break;
2946
2947 case mfDIVINEFIRE:
2948 if(!hints)
2949 {
2950 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sDIVINEFIRE],tmpscr->secretcset[sDIVINEFIRE]);
2951 }
2952 else
2953 {
2954 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2955
2956 if(tempitem<0) break;
2957
2958 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2959 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2960 {
2961 tempitemx=x;
2962 tempitemy=y;
2963 }
2964
2965 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2966 }
2967
2968 break;
2969
2970 case mfARROW:
2971
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2972 {
2973
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sARROW],tmpscr->secretcset[sARROW]);
2974 732 }
2975 else
2976 {
2977 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2978
2979
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2980
2981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2982
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2983 {
2984 61 tempitemx=x;
2985 61 tempitemy=y;
2986 61 }
2987
2988 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2989 }
2990
2991 814 break;
2992
2993 case mfSARROW:
2994 if(!hints)
2995 {
2996 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSARROW],tmpscr->secretcset[sSARROW]);
2997 }
2998 else
2999 {
3000 tempitem=getItemID(itemsbuf,itype_arrow,2);
3001
3002 if(tempitem<0) break;
3003
3004 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3005 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3006 {
3007 tempitemx=x;
3008 tempitemy=y;
3009 }
3010
3011 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3012 }
3013
3014 break;
3015
3016 case mfGARROW:
3017 if(!hints)
3018 {
3019 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sGARROW],tmpscr->secretcset[sGARROW]);
3020 }
3021 else
3022 {
3023 tempitem=getItemID(itemsbuf,itype_arrow,3);
3024
3025 if(tempitem<0) break;
3026
3027 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3028 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3029 {
3030 tempitemx=x;
3031 tempitemy=y;
3032 }
3033
3034 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3035 }
3036
3037 break;
3038
3039 case mfBOMB:
3040
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 16 times.
33 if(!hints)
3041 {
3042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBOMB],tmpscr->secretcset[sBOMB]);
3043 16 }
3044 else
3045 {
3046 //tempitem=getItemID(itemsbuf,itype_bomb,1);
3047 17 tempweapon = wLitBomb;
3048
3049 //if (tempitem<0) break;
3050
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3051
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3052 {
3053 12 tempweaponx=x;
3054 12 tempweapony=y;
3055 12 }
3056
3057 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3058 }
3059
3060 33 break;
3061
3062 case mfSBOMB:
3063
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
3064 {
3065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSBOMB],tmpscr->secretcset[sSBOMB]);
3066 48 }
3067 else
3068 {
3069 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
3070 //if (tempitem<0) break;
3071 48 tempweapon = wLitSBomb;
3072
3073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3074
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3075 {
3076 36 tempweaponx=x;
3077 36 tempweapony=y;
3078 36 }
3079
3080 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3081 }
3082
3083 96 break;
3084
3085 case mfARMOS_SECRET:
3086
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
3087 {
3088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3089 12 }
3090 24 break;
3091
3092 case mfBRANG:
3093
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(!hints)
3094 {
3095 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBRANG],tmpscr->secretcset[sBRANG]);
3096 }
3097 else
3098 {
3099 5 tempitem=getItemID(itemsbuf,itype_brang,1);
3100
3101
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
3102
3103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3104
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3105 {
3106 4 tempitemx=x;
3107 4 tempitemy=y;
3108 4 }
3109
3110 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3111 }
3112
3113 5 break;
3114
3115 case mfMBRANG:
3116 if(!hints)
3117 {
3118 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMBRANG],tmpscr->secretcset[sMBRANG]);
3119 }
3120 else
3121 {
3122 tempitem=getItemID(itemsbuf,itype_brang,2);
3123
3124 if(tempitem<0) break;
3125
3126 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3127 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3128 {
3129 tempitemx=x;
3130 tempitemy=y;
3131 }
3132
3133 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3134 }
3135
3136 break;
3137
3138 case mfFBRANG:
3139 if(!hints)
3140 {
3141 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sFBRANG],tmpscr->secretcset[sFBRANG]);
3142 }
3143 else
3144 {
3145 tempitem=getItemID(itemsbuf,itype_brang,3);
3146
3147 if(tempitem<0) break;
3148
3149 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3150 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3151 {
3152 tempitemx=x;
3153 tempitemy=y;
3154 }
3155
3156 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3157 }
3158
3159 break;
3160
3161 case mfWANDMAGIC:
3162 if(!hints)
3163 {
3164 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDMAGIC],tmpscr->secretcset[sWANDMAGIC]);
3165 }
3166 else
3167 {
3168 tempitem=getItemID(itemsbuf,itype_wand,1);
3169
3170 if(tempitem<0) break;
3171
3172 tempweapon=itemsbuf[tempitem].wpn3;
3173
3174 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3175 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3176 {
3177 tempitemx=x;
3178 tempitemy=y;
3179 }
3180 else
3181 {
3182 tempweaponx=x;
3183 tempweapony=y;
3184 --lens_hint_weapon[wMagic][4];
3185
3186 if(lens_hint_weapon[wMagic][4]<-8)
3187 {
3188 lens_hint_weapon[wMagic][4]=8;
3189 }
3190 }
3191
3192 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3193 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3194 }
3195
3196 break;
3197
3198 case mfREFMAGIC:
3199
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3200 {
3201 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sREFMAGIC],tmpscr->secretcset[sREFMAGIC]);
3202 }
3203 else
3204 {
3205 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3206
3207
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3208
3209 16 tempweapon=ewMagic;
3210
3211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3212
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3213 {
3214 13 tempitemx=x;
3215 13 tempitemy=y;
3216 13 }
3217 else
3218 {
3219 3 tempweaponx=x;
3220 3 tempweapony=y;
3221
3222
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3223 {
3224 1 --lens_hint_weapon[ewMagic][4];
3225 1 }
3226 else
3227 {
3228 2 ++lens_hint_weapon[ewMagic][4];
3229 }
3230
3231
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3232 {
3233 lens_hint_weapon[ewMagic][2]=up;
3234 }
3235
3236
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3237 {
3238 2 lens_hint_weapon[ewMagic][2]=down;
3239 2 }
3240 }
3241
3242 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3243 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3244 }
3245
3246 16 break;
3247
3248 case mfREFFIREBALL:
3249
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3250 {
3251 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sREFFIREBALL],tmpscr->secretcset[sREFFIREBALL]);
3252 }
3253 else
3254 {
3255 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3256
3257
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3258
3259 16 tempweapon=ewFireball;
3260
3261
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3262
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3263 {
3264 12 tempitemx=x;
3265 12 tempitemy=y;
3266 12 tempweaponx=x;
3267 12 tempweapony=y;
3268 12 ++lens_hint_weapon[ewFireball][3];
3269
3270
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3271 {
3272 1 lens_hint_weapon[ewFireball][3]=-8;
3273 1 lens_hint_weapon[ewFireball][4]=8;
3274 1 }
3275
3276
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3277 {
3278 8 ++lens_hint_weapon[ewFireball][4];
3279 8 }
3280 else
3281 {
3282 4 --lens_hint_weapon[ewFireball][4];
3283 }
3284 12 }
3285
3286 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3287 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3288 }
3289
3290 16 break;
3291
3292 case mfSWORD:
3293
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3294 {
3295 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORD],tmpscr->secretcset[sSWORD]);
3296 }
3297 else
3298 {
3299 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3300
3301
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3302
3303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3304
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3305 {
3306 5 tempitemx=x;
3307 5 tempitemy=y;
3308 5 }
3309
3310 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3311 }
3312
3313 7 break;
3314
3315 case mfWSWORD:
3316 if(!hints)
3317 {
3318 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORD],tmpscr->secretcset[sWSWORD]);
3319 }
3320 else
3321 {
3322 tempitem=getItemID(itemsbuf,itype_sword,2);
3323
3324 if(tempitem<0) break;
3325
3326 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3327 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3328 {
3329 tempitemx=x;
3330 tempitemy=y;
3331 }
3332
3333 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3334 }
3335
3336 break;
3337
3338 case mfMSWORD:
3339 if(!hints)
3340 {
3341 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORD],tmpscr->secretcset[sMSWORD]);
3342 }
3343 else
3344 {
3345 tempitem=getItemID(itemsbuf,itype_sword,3);
3346
3347 if(tempitem<0) break;
3348
3349 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3350 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3351 {
3352 tempitemx=x;
3353 tempitemy=y;
3354 }
3355
3356 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3357 }
3358
3359 break;
3360
3361 case mfXSWORD:
3362 if(!hints)
3363 {
3364 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORD],tmpscr->secretcset[sXSWORD]);
3365 }
3366 else
3367 {
3368 tempitem=getItemID(itemsbuf,itype_sword,4);
3369
3370 if(tempitem<0) break;
3371
3372 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3373 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3374 {
3375 tempitemx=x;
3376 tempitemy=y;
3377 }
3378
3379 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3380 }
3381
3382 break;
3383
3384 case mfSWORDBEAM:
3385
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3386 {
3387 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORDBEAM],tmpscr->secretcset[sSWORDBEAM]);
3388 }
3389 else
3390 {
3391 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3392
3393
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3394
3395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3396
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3397 {
3398 11 tempitemx=x;
3399 11 tempitemy=y;
3400 11 }
3401
3402 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3403 }
3404
3405 16 break;
3406
3407 case mfWSWORDBEAM:
3408 if(!hints)
3409 {
3410 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORDBEAM],tmpscr->secretcset[sWSWORDBEAM]);
3411 }
3412 else
3413 {
3414 tempitem=getItemID(itemsbuf,itype_sword,2);
3415
3416 if(tempitem<0) break;
3417
3418 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3419 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3420 {
3421 tempitemx=x;
3422 tempitemy=y;
3423 }
3424
3425 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3426 }
3427
3428 break;
3429
3430 case mfMSWORDBEAM:
3431 if(!hints)
3432 {
3433 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORDBEAM],tmpscr->secretcset[sMSWORDBEAM]);
3434 }
3435 else
3436 {
3437 tempitem=getItemID(itemsbuf,itype_sword,3);
3438
3439 if(tempitem<0) break;
3440
3441 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3442 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3443 {
3444 tempitemx=x;
3445 tempitemy=y;
3446 }
3447
3448 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3449 }
3450
3451 break;
3452
3453 case mfXSWORDBEAM:
3454 if(!hints)
3455 {
3456 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORDBEAM],tmpscr->secretcset[sXSWORDBEAM]);
3457 }
3458 else
3459 {
3460 tempitem=getItemID(itemsbuf,itype_sword,4);
3461
3462 if(tempitem<0) break;
3463
3464 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3465 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3466 {
3467 tempitemx=x;
3468 tempitemy=y;
3469 }
3470
3471 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3472 }
3473
3474 break;
3475
3476 case mfHOOKSHOT:
3477
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3478 {
3479 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sHOOKSHOT],tmpscr->secretcset[sHOOKSHOT]);
3480 }
3481 else
3482 {
3483 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3484
3485
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3486
3487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3488
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3489 {
3490 12 tempitemx=x;
3491 12 tempitemy=y;
3492 12 }
3493
3494 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3495 }
3496
3497 17 break;
3498
3499 case mfWAND:
3500
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3501 {
3502 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWAND],tmpscr->secretcset[sWAND]);
3503 }
3504 else
3505 {
3506 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3507
3508
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3509
3510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3511
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3512 {
3513 28 tempitemx=x;
3514 28 tempitemy=y;
3515 28 }
3516
3517 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3518 }
3519
3520 35 break;
3521
3522 case mfHAMMER:
3523
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3524 {
3525 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sHAMMER],tmpscr->secretcset[sHAMMER]);
3526 }
3527 else
3528 {
3529 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3530
3531
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3532
3533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3534
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3535 {
3536 13 tempitemx=x;
3537 13 tempitemy=y;
3538 13 }
3539
3540 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3541 }
3542
3543 17 break;
3544
3545 case mfARMOS_ITEM:
3546 case mfDIVE_ITEM:
3547
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2064 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2064 if((!getmapflag() || (tmpscr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG3))
3548 {
3549 2064 putitem2(dest,x,y,tmpscr->catchall, lens_hint_item[tmpscr->catchall][0], lens_hint_item[tmpscr->catchall][1], 0);
3550 2064 }
3551 2064 break;
3552
3553 case 16:
3554 case 17:
3555 case 18:
3556 case 19:
3557 case 20:
3558 case 21:
3559 case 22:
3560 case 23:
3561 case 24:
3562 case 25:
3563 case 26:
3564 case 27:
3565 case 28:
3566 case 29:
3567 case 30:
3568 case 31:
3569
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 2610 times.
3618 if(!hints)
3570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2610 times.
5220 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3571 2610 putcombo(dest,x,y,tmpscr->secretcombo[checkflag-16+4],tmpscr->secretcset[checkflag-16+4]);
3572
3573 3618 break;
3574 case mfSECRETSNEXT:
3575 if(!hints)
3576 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3577 putcombo(dest,x,y,tmpscr->data[i]+1,tmpscr->cset[i]);
3578
3579 break;
3580
3581 case mfSTRIKE:
3582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3583 {
3584 906 goto special;
3585 }
3586 else
3587 {
3588 break;
3589 }
3590
3591 28640 default: goto special;
3592
3593 special:
3594
8/8
✓ Branch 0 taken 14677 times.
✓ Branch 1 taken 14869 times.
✓ Branch 2 taken 473 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 441 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29546 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG4)))
3595 {
3596
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6549 times.
✓ Branch 2 taken 4913 times.
✓ Branch 3 taken 1636 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1636 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6549 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3597 {
3598 4913 rectfill(dest,x,y,x+15,y+15,WHITE);
3599 4913 }
3600 6549 }
3601
3602 29546 break;
3603 }
3604 5748864 }
3605 2874432 }
3606
3607
2/2
✓ Branch 0 taken 8166 times.
✓ Branch 1 taken 8166 times.
16332 if(layer)
3608 {
3609
2/2
✓ Branch 0 taken 7978 times.
✓ Branch 1 taken 188 times.
8166 if(tmpscr->door[0]==dWALK)
3610 188 rectfill(dest, 120, 16+playing_field_offset, 135, 31+playing_field_offset, WHITE);
3611
3612
2/2
✓ Branch 0 taken 7969 times.
✓ Branch 1 taken 197 times.
8166 if(tmpscr->door[1]==dWALK)
3613 197 rectfill(dest, 120, 144+playing_field_offset, 135, 159+playing_field_offset, WHITE);
3614
3615
2/2
✓ Branch 0 taken 8014 times.
✓ Branch 1 taken 152 times.
8166 if(tmpscr->door[2]==dWALK)
3616 152 rectfill(dest, 16, 80+playing_field_offset, 31, 95+playing_field_offset, WHITE);
3617
3618
2/2
✓ Branch 0 taken 7940 times.
✓ Branch 1 taken 226 times.
8166 if(tmpscr->door[3]==dWALK)
3619 226 rectfill(dest, 224, 80+playing_field_offset, 239, 95+playing_field_offset, WHITE);
3620
3621
2/2
✓ Branch 0 taken 8123 times.
✓ Branch 1 taken 43 times.
8166 if(tmpscr->door[0]==dBOMB)
3622 {
3623 43 showbombeddoor(dest, 0);
3624 43 }
3625
3626
2/2
✓ Branch 0 taken 8127 times.
✓ Branch 1 taken 39 times.
8166 if(tmpscr->door[1]==dBOMB)
3627 {
3628 39 showbombeddoor(dest, 1);
3629 39 }
3630
3631
1/2
✓ Branch 0 taken 8166 times.
✗ Branch 1 not taken.
8166 if(tmpscr->door[2]==dBOMB)
3632 {
3633 showbombeddoor(dest, 2);
3634 }
3635
3636
2/2
✓ Branch 0 taken 8129 times.
✓ Branch 1 taken 37 times.
8166 if(tmpscr->door[3]==dBOMB)
3637 {
3638 37 showbombeddoor(dest, 3);
3639 37 }
3640 8166 }
3641
3642
2/2
✓ Branch 0 taken 14298 times.
✓ Branch 1 taken 2034 times.
16332 if(tmpscr->stairx + tmpscr->stairy)
3643 {
3644
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if(!hints)
3645 {
3646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3647 1123 putcombo(dest,tmpscr->stairx,tmpscr->stairy+playing_field_offset,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3648 1123 }
3649 else
3650 {
3651
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(tmpscr->flags&fWHISTLE)
3652 {
3653 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3654 48 int32_t tempitemx=-16;
3655 48 int32_t tempitemy=-16;
3656
3657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3658
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3659 {
3660 24 tempitemx=tmpscr->stairx;
3661 24 tempitemy=tmpscr->stairy+playing_field_offset;
3662 24 }
3663
3664 48 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3665 48 }
3666 }
3667 2034 }
3668 }
3669 16332 }
3670
3671 BITMAP *lens_scr_d; // The "d" is for "destructible"!
3672
3673 7997 void draw_lens_over()
3674 {
3675 // Oh, what the heck.
3676 static BITMAP *lens_scr = NULL;
3677 static int32_t last_width = -1;
3678 7997 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3679
3680 // Only redraw the circle if the size has changed
3681
2/2
✓ Branch 0 taken 7987 times.
✓ Branch 1 taken 10 times.
7997 if(width != last_width)
3682 {
3683
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(lens_scr == NULL)
3684 {
3685 10 lens_scr = create_bitmap_ex(8,2*288,2*(240-playing_field_offset));
3686 10 }
3687
3688 10 clear_to_color(lens_scr, BLACK);
3689 10 circlefill(lens_scr, 288, 240-playing_field_offset, width, 0);
3690 10 circle(lens_scr, 288, 240-playing_field_offset, width+2, 0);
3691 10 circle(lens_scr, 288, 240-playing_field_offset, width+5, 0);
3692 10 last_width=width;
3693 10 }
3694
3695 7997 masked_blit(lens_scr, framebuf, 288-(HeroX()+8), 240-playing_field_offset-(HeroY()+8), 0, playing_field_offset, 256, 168);
3696 7997 do_primitives(framebuf, SPLAYER_LENS_OVER, tmpscr, 0, playing_field_offset);
3697 7997 }
3698
3699 //----------------------------------------------------------------
3700
3701 31111 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3702 {
3703 //recreating a big bitmap every frame is highly sluggish.
3704
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 31108 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
31111 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3705 31111 clear_to_color(wavebuf, BLACK);
3706 31111 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,224-original_playing_field_offset);
3707
3708 int32_t ofs;
3709 // int32_t amplitude=8;
3710 // int32_t wavelength=4;
3711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31111 times.
31111 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3712
3/6
✓ Branch 0 taken 31111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31111 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 31111 times.
31111 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3713 31111 int32_t amp2=168;
3714
2/4
✓ Branch 0 taken 31111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31111 times.
31111 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3715 31111 int32_t i=frame%amp2;
3716
3717
2/2
✓ Branch 0 taken 5226648 times.
✓ Branch 1 taken 31111 times.
5257759 for(int32_t j=0; j<168; j++)
3718 {
3719
3/4
✓ Branch 0 taken 2613324 times.
✓ Branch 1 taken 2613324 times.
✓ Branch 2 taken 2613324 times.
✗ Branch 3 not taken.
5226648 if(j&1 && interpol)
3720 {
3721 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3722 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3723 }
3724 else
3725 {
3726 5226648 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3727 }
3728
3729
1/2
✓ Branch 0 taken 5226648 times.
✗ Branch 1 not taken.
5226648 if(ofs)
3730 {
3731
2/2
✓ Branch 0 taken 1338021888 times.
✓ Branch 1 taken 5226648 times.
1343248536 for(int32_t k=0; k<256; k++)
3732 {
3733 1338021888 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3734 1338021888 }
3735 5226648 }
3736 5226648 }
3737 31111 }
3738
3739 4848 void draw_fuzzy(int32_t fuzz)
3740 // draws from right half of scrollbuf to framebuf
3741 {
3742 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3743 byte *start, *si, *di;
3744
3745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4848 times.
4848 if(fuzz<1)
3746 fuzz = 1;
3747
3748 4848 xstep = 128%fuzz;
3749
3750
2/2
✓ Branch 0 taken 1010 times.
✓ Branch 1 taken 3838 times.
4848 if(xstep > 0)
3751 3838 xstep = fuzz-xstep;
3752
3753 4848 ystep = 112%fuzz;
3754
3755
2/2
✓ Branch 0 taken 1414 times.
✓ Branch 1 taken 3434 times.
4848 if(ystep > 0)
3756 3434 ystep = fuzz-ystep;
3757
3758 4848 firsty = 1;
3759
3760
2/2
✓ Branch 0 taken 4848 times.
✓ Branch 1 taken 174932 times.
179780 for(y=0; y<224;)
3761 {
3762 174932 start = &(scrollbuf->line[y][256]);
3763
3764
4/4
✓ Branch 0 taken 172508 times.
✓ Branch 1 taken 1088376 times.
✓ Branch 2 taken 1085952 times.
✓ Branch 3 taken 174932 times.
1260884 for(dy=0; dy<ystep && dy+y<224; dy++)
3765 {
3766 1085952 si = start;
3767 1085952 di = &(framebuf->line[y+dy][0]);
3768 1085952 i = xstep;
3769 1085952 firstx = 1;
3770
3771
2/2
✓ Branch 0 taken 278003712 times.
✓ Branch 1 taken 1085952 times.
279089664 for(dx=0; dx<256; dx++)
3772 {
3773 278003712 *(di++) = *si;
3774
3775
2/2
✓ Branch 0 taken 234248896 times.
✓ Branch 1 taken 43754816 times.
278003712 if(++i >= fuzz)
3776 {
3777
2/2
✓ Branch 0 taken 42668864 times.
✓ Branch 1 taken 1085952 times.
43754816 if(!firstx)
3778 42668864 si += fuzz;
3779 else
3780 {
3781 1085952 si += fuzz-xstep;
3782 1085952 firstx = 0;
3783 }
3784
3785 43754816 i = 0;
3786 43754816 }
3787 278003712 }
3788 1085952 }
3789
3790
2/2
✓ Branch 0 taken 170084 times.
✓ Branch 1 taken 4848 times.
174932 if(!firsty)
3791 170084 y += fuzz;
3792 else
3793 {
3794 4848 y += ystep;
3795 4848 ystep = fuzz;
3796 4848 firsty = 0;
3797 }
3798 }
3799 4848 }
3800
3801 9286296 void updatescr(bool allowwavy)
3802 {
3803
4/6
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 9286180 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 116 times.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
9286296 static BITMAP *wavybuf = create_bitmap_ex(8,256,224);
3804
4/6
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 9286180 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 116 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 116 times.
9286296 static BITMAP *panorama = create_bitmap_ex(8,256,224);
3805
3806
2/2
✓ Branch 0 taken 9259531 times.
✓ Branch 1 taken 26765 times.
9286296 if(toogam)
3807 {
3808 26765 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3809 26765 }
3810
3811
1/2
✓ Branch 0 taken 9286296 times.
✗ Branch 1 not taken.
9286296 if(Showpal)
3812 dump_pal(framebuf);
3813
3814
2/2
✓ Branch 0 taken 8985064 times.
✓ Branch 1 taken 301232 times.
9286296 if(!Playing)
3815 301232 black_opening_count=0;
3816
3817
2/2
✓ Branch 0 taken 9212970 times.
✓ Branch 1 taken 73326 times.
9286296 if(black_opening_count<0) //shape is opening up
3818 {
3819 73326 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3820
3821
2/4
✓ Branch 0 taken 73326 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73326 times.
73326 if(Advance||(!Paused))
3822 {
3823 73326 ++black_opening_count;
3824 73326 }
3825 73326 }
3826
2/2
✓ Branch 0 taken 9186834 times.
✓ Branch 1 taken 26136 times.
9212970 else if(black_opening_count>0) //shape is closing
3827 {
3828 26136 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3829
3830
2/4
✓ Branch 0 taken 26136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26136 times.
26136 if(Advance||(!Paused))
3831 {
3832 26136 --black_opening_count;
3833 26136 }
3834 26136 }
3835
3836
3/4
✓ Branch 0 taken 9188341 times.
✓ Branch 1 taken 97955 times.
✓ Branch 2 taken 9188341 times.
✗ Branch 3 not taken.
9286296 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3837 {
3838 black_opening_shape = bosCIRCLE;
3839 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3840 refreshTints();
3841 refreshpal=true;
3842 }
3843
3844
2/2
✓ Branch 0 taken 9032096 times.
✓ Branch 1 taken 254200 times.
9286296 if(refreshpal)
3845 {
3846 254200 refreshpal=false;
3847 254200 RAMpal[253] = _RGB(0,0,0);
3848 254200 RAMpal[254] = _RGB(63,63,63);
3849 254200 hw_palette = &RAMpal;
3850 254200 update_hw_pal = true;
3851
3852 254200 create_rgb_table(&rgb_table, RAMpal, NULL);
3853 254200 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
3854 254200 memcpy(&trans_table2, &trans_table, sizeof(COLOR_MAP));
3855
3856
2/2
✓ Branch 0 taken 65075200 times.
✓ Branch 1 taken 254200 times.
65329400 for(int32_t q=0; q<PAL_SIZE; q++)
3857 {
3858 65075200 trans_table2.data[0][q] = q;
3859 65075200 trans_table2.data[q][q] = q;
3860 65075200 }
3861 254200 }
3862
3863 9286296 bool clearwavy = (wavy <= 0);
3864
3865
2/2
✓ Branch 0 taken 7655 times.
✓ Branch 1 taken 9278641 times.
9286296 if(wavy <= 0)
3866 {
3867 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3868 9278641 wavy = (DMaps[currdmap].flags&dmfWAVY ? 4 : 0);
3869 9278641 }
3870
3871 9286296 blit(framebuf, wavybuf, 0, 0, 0, 0, 256, 224);
3872
3873
6/6
✓ Branch 0 taken 31361 times.
✓ Branch 1 taken 9254935 times.
✓ Branch 2 taken 31239 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31111 times.
9286296 if(wavy && Playing && allowwavy)
3874 {
3875 31111 draw_wavy(framebuf, wavybuf, wavy,false);
3876 31111 }
3877
3878
2/2
✓ Branch 0 taken 9278641 times.
✓ Branch 1 taken 7655 times.
9286296 if(clearwavy)
3879 9278641 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3880
2/4
✓ Branch 0 taken 7655 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7655 times.
7655 else if(Playing && !Paused)
3881 7655 wavy--; // Wavy was set by a script. Decrement it.
3882
3883
5/6
✓ Branch 0 taken 8985064 times.
✓ Branch 1 taken 301232 times.
✓ Branch 2 taken 259415 times.
✓ Branch 3 taken 8725649 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 259415 times.
9286296 if(Playing && msgpos && !screenscrolling)
3884 {
3885
1/2
✓ Branch 0 taken 259415 times.
✗ Branch 1 not taken.
259415 if(!(msg_bg_display_buf->clip))
3886 259415 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,168);
3887
1/2
✓ Branch 0 taken 259415 times.
✗ Branch 1 not taken.
259415 if(!(msg_portrait_display_buf->clip))
3888 259415 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,168);
3889
1/2
✓ Branch 0 taken 259415 times.
✗ Branch 1 not taken.
259415 if(!(msg_txt_display_buf->clip))
3890 259415 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,168);
3891 259415 }
3892
3893 /*
3894 if(!(msg_txt_display_buf->clip) && Playing && msgpos && !screenscrolling)
3895 {
3896 BITMAP* subBmp = 0;
3897 masked_blit(msg_txt_display_buf,subBmp,0,0,0,playing_field_offset,256,168);
3898 // masked_blit(msg_txt_display_buf,subBmp,0,playing_field_offset,256,168);
3899 draw_trans_sprite(framebuf, subBmp, 0, playing_field_offset);
3900 destroy_bitmap(subBmp);
3901 //void draw_sprite_ex(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t mode, int32_t flip);
3902 // masked_blit(msg_txt_display_buf,framebuf,0,0,0,playing_field_offset,256,168);
3903 //void masked_blit(BITMAP *source, BITMAP *dest, int32_t source_x, int32_t source_y, int32_t dest_x, int32_t dest_y, int32_t width, int32_t height);
3904 }
3905 */
3906
3907
2/2
✓ Branch 0 taken 9245239 times.
✓ Branch 1 taken 41057 times.
9286296 bool nosubscr = (tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET));
3908
3909
2/2
✓ Branch 0 taken 9249864 times.
✓ Branch 1 taken 36432 times.
9286296 if(nosubscr)
3910 {
3911 36432 rectfill(panorama,0,0,255,passive_subscreen_height/2,0);
3912 36432 rectfill(panorama,0,168+passive_subscreen_height/2,255,168+passive_subscreen_height-1,0);
3913 36432 blit(wavybuf,panorama,0,playing_field_offset,0,passive_subscreen_height/2,256,224-passive_subscreen_height);
3914 36432 }
3915
3916 //TODO: Optimize blit 'overcalls' -Gleeok
3917
2/2
✓ Branch 0 taken 36432 times.
✓ Branch 1 taken 9249864 times.
9286296 BITMAP *source = nosubscr ? panorama : wavybuf;
3918 9286296 blit(source,framebuf,0,0,0,0,256,224);
3919
3920 9286296 update_hw_screen();
3921 9286296 }
3922
3923 //----------------------------------------------------------------
3924
3925 static PALETTE syspal;
3926 int32_t onGUISnapshot()
3927 {
3928 char buf[200];
3929 int32_t num=0;
3930 bool realpal=(CHECK_CTRL_CMD);
3931 do
3932 {
3933 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3934 }
3935 while(num<99999 && exists(buf));
3936
3937 BITMAP *b = create_bitmap_ex(8,resx,resy);
3938
3939 if(b)
3940 {
3941 blit(screen,b,0,0,0,0,resx,resy);
3942 save_bitmap(buf,screen,RAMpal);
3943 destroy_bitmap(b);
3944 }
3945
3946 return D_O_K;
3947 }
3948
3949 int32_t onNonGUISnapshot()
3950 {
3951 PALETTE temppal;
3952 get_palette(temppal);
3953 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3954
3955 char buf[200];
3956 int32_t num=0;
3957
3958 do
3959 {
3960 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3961 }
3962 while(num<99999 && exists(buf));
3963
3964 if (tmpscr->flags3&fNOSUBSCR && !(key[KEY_ALT]))
3965 {
3966 BITMAP *b = create_bitmap_ex(8,256,168);
3967 clear_to_color(b,0);
3968 blit(framebuf,b,0,passive_subscreen_height/2,0,0,256,168);
3969 save_bitmap(buf,b,realpal?temppal:RAMpal);
3970 destroy_bitmap(b);
3971 }
3972 else
3973 {
3974 save_bitmap(buf,framebuf,realpal?temppal:RAMpal);
3975 }
3976
3977 return D_O_K;
3978 }
3979
3980 int32_t onSnapshot()
3981 {
3982 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3983 {
3984 onGUISnapshot();
3985 }
3986 else
3987 {
3988 onNonGUISnapshot();
3989 }
3990
3991 return D_O_K;
3992 }
3993
3994 int32_t onSaveMapPic()
3995 {
3996 int32_t mapres2 = 0;
3997 char buf[200];
3998 int32_t num=0;
3999 mapscr tmpscr_b[2];
4000 mapscr tmpscr_c[6];
4001 BITMAP* _screen_draw_buffer = NULL;
4002 _screen_draw_buffer = create_bitmap_ex(8,256,224);
4003 set_clip_state(_screen_draw_buffer,1);
4004
4005 for(int32_t i=0; i<6; ++i)
4006 {
4007 tmpscr_c[i] = tmpscr2[i];
4008 tmpscr2[i].zero_memory();
4009
4010 if(i>=2)
4011 {
4012 continue;
4013 }
4014
4015 tmpscr_b[i] = tmpscr[i];
4016 tmpscr[i].zero_memory();
4017 }
4018
4019 do
4020 {
4021 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
4022 }
4023 while(num<99999 && exists(buf));
4024
4025 BITMAP* mappic = NULL;
4026
4027
4028 bool done=false, redraw=true;
4029
4030 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
4031
4032 if(!mappic)
4033 {
4034 enter_sys_pal();
4035 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4036 exit_sys_pal();
4037 return D_O_K;;
4038 }
4039
4040 // draw the map
4041 set_clip_rect(_screen_draw_buffer, 0, 0, _screen_draw_buffer->w, _screen_draw_buffer->h);
4042
4043 for(int32_t y=0; y<8; y++)
4044 {
4045 for(int32_t x=0; x<16; x++)
4046 {
4047 if(!displayOnMap(x, y))
4048 {
4049 rectfill(_screen_draw_buffer, 0, 0, 255, 223, WHITE);
4050 }
4051 else
4052 {
4053 int32_t s = (y<<4) + x;
4054 loadscr2(1,s,-1);
4055
4056 for(int32_t i=0; i<6; i++)
4057 {
4058 if(tmpscr[1].layermap[i]<=0)
4059 continue;
4060
4061 tmpscr2[i]=TheMaps[(tmpscr[1].layermap[i]-1)*MAPSCRS+tmpscr[1].layerscreen[i]];
4062 }
4063
4064 if(XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
4065
4066 if(XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
4067
4068 if(lenscheck(tmpscr+1,0)) putscr(_screen_draw_buffer,256,0,tmpscr+1);
4069 do_layer(_screen_draw_buffer, 0, 1, tmpscr+1, -256, playing_field_offset, 2);
4070
4071 if(!XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
4072
4073 putscrdoors(_screen_draw_buffer,256,0,tmpscr+1);
4074 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4075 {
4076 do_layer(_screen_draw_buffer, -2, 0, tmpscr+1, -256, playing_field_offset, 2);
4077 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
4078 {
4079 do_layer(_screen_draw_buffer, -2, 1, tmpscr+1, -256, playing_field_offset, 2);
4080 do_layer(_screen_draw_buffer, -2, 2, tmpscr+1, -256, playing_field_offset, 2);
4081 }
4082 }
4083 do_layer(_screen_draw_buffer, -3, 0, tmpscr+1, -256, playing_field_offset, 2); // Freeform combos!
4084
4085 if(!XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
4086
4087 do_layer(_screen_draw_buffer, 0, 4, tmpscr+1, -256, playing_field_offset, 2);
4088 do_layer(_screen_draw_buffer, -1, 0, tmpscr+1, -256, playing_field_offset, 2);
4089 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
4090 {
4091 do_layer(_screen_draw_buffer, -1, 1, tmpscr+1, -256, playing_field_offset, 2);
4092 do_layer(_screen_draw_buffer, -1, 2, tmpscr+1, -256, playing_field_offset, 2);
4093 }
4094 do_layer(_screen_draw_buffer, 0, 5, tmpscr+1, -256, playing_field_offset, 2);
4095 do_layer(_screen_draw_buffer, 0, 6, tmpscr+1, -256, playing_field_offset, 2);
4096
4097 }
4098
4099 stretch_blit(_screen_draw_buffer, mappic, 256, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
4100 }
4101 }
4102
4103 for(int32_t i=0; i<6; ++i)
4104 {
4105 tmpscr2[i]=tmpscr_c[i];
4106
4107 if(i>=2)
4108 {
4109 continue;
4110 }
4111
4112 tmpscr[i]=tmpscr_b[i];
4113 }
4114
4115 save_bitmap(buf,mappic,RAMpal);
4116 destroy_bitmap(mappic);
4117 destroy_bitmap(_screen_draw_buffer);
4118 return D_O_K;
4119 }
4120
4121 14 void f_Quit(int32_t type)
4122 {
4123
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
14 if(type==qQUIT && !Playing)
4124 return;
4125
4126 14 bool from_menu = is_sys_pal;
4127
4128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(!from_menu)
4129 {
4130 14 music_pause();
4131 14 pause_all_sfx();
4132 14 sys_mouse();
4133 14 }
4134 14 enter_sys_pal();
4135 14 clear_keybuf();
4136
4137
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (replay_version_check(0, 10))
4138 13 replay_poll();
4139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (replay_is_replaying())
4140 14 replay_peek_quit();
4141
4142
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if (!replay_is_replaying())
4143 switch(type)
4144 {
4145 case qQUIT:
4146 onQuit();
4147 break;
4148
4149 case qRESET:
4150 onReset();
4151 break;
4152
4153 case qEXIT:
4154 onExit();
4155 break;
4156 }
4157
4158
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(Quit)
4159 {
4160 14 kill_sfx();
4161 14 music_stop();
4162 14 exit_sys_pal();
4163 14 update_hw_screen();
4164 14 }
4165 else
4166 {
4167 exit_sys_pal();
4168 if(!from_menu)
4169 {
4170 music_resume();
4171 resume_all_sfx();
4172 }
4173 }
4174
4175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(!from_menu)
4176 14 game_mouse();
4177 14 eat_buttons();
4178
4179 14 zc_readrawkey(KEY_ESC);
4180
4181 14 zc_readrawkey(KEY_ENTER);
4182 14 }
4183
4184 //----------------------------------------------------------------
4185
4186 int32_t onNoWalls()
4187 {
4188 cheats_enqueue(Cheat::Walls);
4189 return D_O_K;
4190 }
4191
4192 int32_t onIgnoreSideview()
4193 {
4194 cheats_enqueue(Cheat::IgnoreSideView);
4195 return D_O_K;
4196 }
4197
4198 9286170 int32_t input_idle(bool checkmouse)
4199 {
4200 static int32_t mx, my, mz, mb;
4201
4202
4/6
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461515 times.
✓ Branch 3 taken 6824655 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2461515 times.
11747685 if(keypressed() || zc_key_pressed() ||
4203
4/8
✓ Branch 0 taken 2461515 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461515 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2461515 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2461515 times.
✗ Branch 7 not taken.
2461515 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4204 {
4205 6824655 idle_count = 0;
4206
4207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6824655 times.
6824655 if(active_count < MAX_ACTIVE)
4208 {
4209 6824655 ++active_count;
4210 6824655 }
4211 6824655 }
4212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2461515 times.
2461515 else if(idle_count < MAX_IDLE)
4213 {
4214 2461515 ++idle_count;
4215 2461515 active_count = 0;
4216 2461515 }
4217
4218 9286170 mx = mouse_x;
4219 9286170 my = mouse_y;
4220 9286170 mz = mouse_z;
4221 9286170 mb = mouse_b;
4222
4223 9286170 return idle_count;
4224 }
4225
4226 int32_t onGoFast()
4227 {
4228 cheats_enqueue(Cheat::Fast);
4229 return D_O_K;
4230 }
4231
4232 int32_t onKillCheat()
4233 {
4234 cheats_enqueue(Cheat::Kill);
4235 return D_O_K;
4236 }
4237
4238 int32_t onSecretsCheat()
4239 {
4240 cheats_enqueue(Cheat::TrigSecrets);
4241 return D_O_K;
4242 }
4243 int32_t onSecretsCheatPerm()
4244 {
4245 cheats_enqueue(Cheat::TrigSecretsPerm);
4246 return D_O_K;
4247 }
4248
4249 int32_t onShowLayer0()
4250 {
4251 show_layer_0 = !show_layer_0;
4252 return D_O_K;
4253 }
4254 int32_t onShowLayer1()
4255 {
4256 show_layer_1 = !show_layer_1;
4257 return D_O_K;
4258 }
4259 int32_t onShowLayer2()
4260 {
4261 show_layer_2 = !show_layer_2;
4262 return D_O_K;
4263 }
4264 int32_t onShowLayer3()
4265 {
4266 show_layer_3 = !show_layer_3;
4267 return D_O_K;
4268 }
4269 int32_t onShowLayer4()
4270 {
4271 show_layer_4 = !show_layer_4;
4272 return D_O_K;
4273 }
4274 int32_t onShowLayer5()
4275 {
4276 show_layer_5 = !show_layer_5;
4277 return D_O_K;
4278 }
4279 int32_t onShowLayer6()
4280 {
4281 show_layer_6 = !show_layer_6;
4282 return D_O_K;
4283 }
4284 int32_t onShowLayerO()
4285 {
4286 show_layer_over=!show_layer_over;
4287 return D_O_K;
4288 }
4289 int32_t onShowLayerP()
4290 {
4291 show_layer_push=!show_layer_push;
4292 return D_O_K;
4293 }
4294 int32_t onShowLayerS()
4295 {
4296 show_sprites=!show_sprites;
4297 return D_O_K;
4298 }
4299 int32_t onShowLayerF()
4300 {
4301 show_ffcs=!show_ffcs;
4302 return D_O_K;
4303 }
4304 int32_t onShowLayerW()
4305 {
4306 show_walkflags=!show_walkflags;
4307 if(show_walkflags)
4308 show_effectflags = false;
4309 return D_O_K;
4310 }
4311 int32_t onShowLayerE()
4312 {
4313 show_effectflags=!show_effectflags;
4314 if(show_effectflags)
4315 show_walkflags = false;
4316 return D_O_K;
4317 }
4318 int32_t onShowFFScripts()
4319 {
4320 show_ff_scripts=!show_ff_scripts;
4321 return D_O_K;
4322 }
4323 int32_t onShowHitboxes()
4324 {
4325 show_hitboxes=!show_hitboxes;
4326 return D_O_K;
4327 }
4328 int32_t onShowInfoOpacity()
4329 {
4330 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4331 zc_set_config("zc","debug_info_opacity",info_opacity);
4332 return D_O_K;
4333 }
4334
4335 int32_t onLightSwitch()
4336 {
4337 cheats_enqueue(Cheat::Light);
4338 return D_O_K;
4339 }
4340
4341 int32_t onGoTo();
4342 int32_t onGoToComplete();
4343
4344 9286170 bool handle_close_btn_quit()
4345 {
4346
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(close_button_quit)
4347 {
4348 close_button_quit=false;
4349 f_Quit(qEXIT);
4350 }
4351 9286170 return (exiting_program = Quit==qEXIT);
4352 }
4353
4354 9286170 void syskeys()
4355 {
4356 9286170 update_system_keys();
4357
4358 int32_t oldtitle_version;
4359
4360 9286170 poll_joystick();
4361
4362 9286170 handle_close_btn_quit();
4363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
9286170 if(Quit == qEXIT) return;
4364
4365
2/10
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9286170 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
9286170 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4366 {
4367 System();
4368 }
4369
4370 9286170 mouse_down=gui_mouse_b();
4371
4372
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(zc_read_system_key(KEY_F1))
4373 {
4374 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4375 {
4376 halt=!halt;
4377 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4378 }
4379 else
4380 {
4381 Throttlefps=!Throttlefps;
4382 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4383 }
4384 }
4385
4386 // if(zc_readkey(KEY_F1)) Vsync=!Vsync;
4387 /*
4388 if(zc_readkey(KEY_F1)) set_bit(QHeader.rules4,qr4_NEWENEMYTILES,
4389 1-((get_bit(QHeader.rules4,qr4_NEWENEMYTILES))));
4390 */
4391
4392
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(zc_read_system_key(KEY_F2))
4393 {
4394 ShowFPS=!ShowFPS;
4395 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4396 }
4397
4398
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9286170 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4399
4400
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9286170 if(zc_read_system_key(KEY_F4) && Playing)
4401 {
4402 Paused=true;
4403 Advance=true;
4404 }
4405
4406
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(zc_read_system_key(KEY_F6)) onTryQuit();
4407
4408 #ifndef ALLEGRO_MACOSX
4409
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4410
4411
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4412 #else
4413 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4414
4415 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4416 #endif
4417
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9286170 if(zc_read_system_key(KEY_F5)&&(Playing && currscr<128 && DMaps[currdmap].flags&dmfVIEWMAP)) onSaveMapPic();
4418
4419
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if (zc_read_system_key(KEY_F12))
4420 {
4421 onSnapshot();
4422 }
4423
4424
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9286170 if(debug_enabled && zc_read_system_key(KEY_TAB))
4425 set_debug(!get_debug());
4426
4427
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(CheatModifierKeys())
4428 {
4429 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4430 {
4431 if(!bindable_cheat(c))
4432 continue;
4433 if(get_debug() || cheat >= cheat_lvl(c))
4434 {
4435 if(checkcheat(c))
4436 cheats_hit_bind(c);
4437 }
4438 }
4439 }
4440
4441
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(volkeys)
4442 {
4443 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4444
4445 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4446
4447 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4448
4449 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4450 }
4451
4452
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9286170 if(!get_debug() || !SystemKeys || replay_is_replaying())
4453 9286170 goto bottom;
4454
4455 if(zc_readkey(KEY_D))
4456 {
4457 details = !details;
4458 rectfill(screen,0,0,319,7,BLACK);
4459 rectfill(screen,0,8,31,239,BLACK);
4460 rectfill(screen,288,8,319,239,BLACK);
4461 rectfill(screen,32,232,287,239,BLACK);
4462 }
4463
4464 if(zc_readkey(KEY_P)) Paused=!Paused;
4465
4466 //if(zc_readkey(KEY_P)) centerHero();
4467 if(zc_readkey(KEY_A))
4468 {
4469 Paused=true;
4470 Advance=true;
4471 }
4472
4473 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4474 #ifndef ALLEGRO_MACOSX
4475 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4476
4477 if(zc_readkey(KEY_F7))
4478 {
4479 Matrix(ss_speed, ss_density, 0);
4480 game_pal();
4481 }
4482 #else
4483 // The reason these are different on Mac in the first place is that
4484 // the OS doesn't let us use F9 and F10...
4485 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4486
4487 if(zc_readkey(KEY_F9))
4488 {
4489 Matrix(ss_speed, ss_density, 0);
4490 game_pal();
4491 }
4492 #endif
4493 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4494 {
4495 //change containers
4496 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4497 {
4498 //magic containers
4499 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4500 {
4501 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4502 }
4503 else
4504 {
4505 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4506 }
4507 }
4508 else
4509 {
4510 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4511 {
4512 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4513 }
4514 else
4515 {
4516 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4517 }
4518 }
4519 }
4520
4521 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4522 {
4523 //change containers
4524 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4525 {
4526 //magic containers
4527 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4528 {
4529 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4530 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4531 //heart containers
4532 }
4533 else
4534 {
4535 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4536 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4537 }
4538 }
4539 else
4540 {
4541 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4542 {
4543 game->set_magic(zc_max(game->get_magic()-1,0));
4544 }
4545 else
4546 {
4547 game->set_life(zc_max(game->get_life()-1,0));
4548 }
4549 }
4550 }
4551
4552 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4553
4554 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4555
4556 verifyBothWeapons();
4557
4558 bottom:
4559
4560
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(input_idle(true) > after_time())
4561 {
4562 Matrix(ss_speed, ss_density, 0);
4563 game_pal();
4564 }
4565 9286170 }
4566
4567 705783 void checkQuitKeys()
4568 {
4569 #ifndef ALLEGRO_MACOSX
4570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 705783 times.
705783 if(key[KEY_F9]) f_Quit(qRESET);
4571
4572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 705783 times.
705783 if(key[KEY_F10]) f_Quit(qEXIT);
4573 #else
4574 if(key[KEY_F7]) f_Quit(qRESET);
4575
4576 if(key[KEY_F8]) f_Quit(qEXIT);
4577 #endif
4578 705783 }
4579
4580 9286170 bool CheatModifierKeys()
4581 {
4582 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4583 // to trigger cheats.
4584
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if (replay_is_replaying())
4585 9286170 return false;
4586
4587 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4588 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4589 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4590 {
4591 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4592 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4593 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4594 {
4595 return true;
4596 }
4597 }
4598 return false;
4599 9286170 }
4600
4601 //99:05:54, for some reason?
4602 #define OLDMAXTIME 21405240
4603 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4604 #define MAXTIME 1944000000
4605
4606 9286296 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4607 {
4608
1/2
✓ Branch 0 taken 9286296 times.
✗ Branch 1 not taken.
9286296 if(zcmusic!=NULL)
4609 {
4610 zcmusic_poll();
4611 }
4612 9286296 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4613
4614 9286296 updatescr(allowwavy);
4615
4616 9286296 Advance=false;
4617
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9286296 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9286296 times.
9286296 while(Paused && !Advance && !Quit)
4618 {
4619 // have to call this, otherwise we'll get an infinite loop
4620 syskeys();
4621 if(allowF6Script)
4622 {
4623 FFCore.runF6Engine();
4624 }
4625 zc_throttle_fps();
4626
4627 #ifdef _WIN32
4628
4629 if(use_dwm_flush)
4630 {
4631 do_DwmFlush();
4632 }
4633
4634 #endif
4635
4636 // to keep music playing
4637 if(zcmusic!=NULL)
4638 {
4639 zcmusic_poll();
4640 }
4641
4642 update_hw_screen();
4643 }
4644
4645
2/2
✓ Branch 0 taken 9286184 times.
✓ Branch 1 taken 112 times.
9286296 if(Quit)
4646 112 return;
4647
4648
3/4
✓ Branch 0 taken 8985055 times.
✓ Branch 1 taken 301129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8985055 times.
9286184 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4649 8985055 game->change_time(1);
4650
4651 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4652
4653 9286184 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4654
2/2
✓ Branch 0 taken 20428 times.
✓ Branch 1 taken 9265756 times.
9286184 if (replay_version_check(0, 16))
4655 9265756 should_reset_down_state = replay_version_check(11, 16);
4656
2/2
✓ Branch 0 taken 6948639 times.
✓ Branch 1 taken 2337545 times.
9286184 if (should_reset_down_state)
4657 {
4658
2/2
✓ Branch 0 taken 42075810 times.
✓ Branch 1 taken 2337545 times.
44413355 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4659 42075810 down_control_states[i] = raw_control_state[i];
4660 2337545 }
4661
4662
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9286170 times.
9286184 if (replay_is_active())
4663 {
4664
2/2
✓ Branch 0 taken 1270449 times.
✓ Branch 1 taken 8015721 times.
9286170 if (replay_version_check(3))
4665 8015721 replay_poll();
4666
4667
4/4
✓ Branch 0 taken 6945057 times.
✓ Branch 1 taken 2341113 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 6844522 times.
9286170 if (replay_version_check(11) || replay_version_check(6, 8))
4668 2441648 replay_peek_input();
4669 9286170 }
4670
4671 9286184 load_control_called_this_frame = false;
4672
4673 9286184 poll_keyboard();
4674 9286184 update_keys();
4675
4676 9286184 ++frame;
4677
4678
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9286170 times.
9286184 if (replay_is_replaying())
4679 9286170 replay_do_cheats();
4680 9286184 syskeys();
4681
4682 // The mouse variables can change from the mouse thread at anytime during a frame,
4683 // so save the result at the start so that replaying is consistent.
4684 9286184 script_mouse_x = gui_mouse_x();
4685 9286184 script_mouse_y = gui_mouse_y();
4686 9286184 script_mouse_z = mouse_z;
4687 9286184 script_mouse_b = mouse_b;
4688
4689 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4690 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4691 // approach here means it doesn't matter which call adds the cheat.
4692 9286184 cheats_execute_queued();
4693
4694
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9286170 times.
9286184 if (replay_is_replaying())
4695 9286170 replay_peek_quit();
4696
2/2
✓ Branch 0 taken 9286170 times.
✓ Branch 1 taken 14 times.
9286184 if (GameFlags & GAMEFLAG_TRYQUIT)
4697 14 replay_step_quit(0);
4698
2/2
✓ Branch 0 taken 2934 times.
✓ Branch 1 taken 9283250 times.
9286184 if(allowF6Script)
4699 9283250 FFCore.runF6Engine();
4700
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 9285884 times.
9286184 if (Quit)
4701 300 replay_step_quit(Quit);
4702 // Someday... maybe install a Turbo button here?
4703 9286184 zc_throttle_fps();
4704
4705 #ifdef _WIN32
4706
4707 if(use_dwm_flush)
4708 {
4709 do_DwmFlush();
4710 }
4711
4712 #endif
4713
4714 //textprintf_ex(screen,font,0,72,254,BLACK,"%d %d", lastentrance, lastentrance_dmap);
4715
2/2
✓ Branch 0 taken 68758 times.
✓ Branch 1 taken 9217426 times.
9286184 if(sfxcleanup)
4716 9217426 sfx_cleanup();
4717
4718 9286184 jit_poll();
4719
4720 #ifdef __EMSCRIPTEN__
4721 // Yield the main thread back to the browser occasionally.
4722 if (is_headless())
4723 {
4724 static int rate = 10000;
4725 static int force_yield = rate;
4726 if (force_yield++ >= rate)
4727 {
4728 force_yield = 0;
4729 emscripten_sleep(0);
4730 }
4731 }
4732 #endif
4733
4734
4/6
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 9286068 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 116 times.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
9286184 static bool test_mode_auto_restart = zc_get_config("zeldadx", "test_mode_auto_restart", false);
4735
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9286184 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9286184 if (zqtesting_mode && test_mode_auto_restart)
4736 {
4737 static auto last_write_time = fs::last_write_time(qstpath);
4738 static auto last_check = std::chrono::system_clock::now();
4739
4740 if (std::chrono::system_clock::now() - last_check > 200ms)
4741 {
4742 last_check = std::chrono::system_clock::now();
4743 auto write_time = fs::last_write_time(qstpath);
4744 if (last_write_time != write_time)
4745 {
4746 last_write_time = write_time;
4747 disableClickToFreeze = false;
4748 Quit = qRESET;
4749 replay_quit();
4750 }
4751 }
4752 }
4753 9286296 }
4754
4755 101 void zapout()
4756 {
4757 101 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4758 101 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4759
4760 101 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4761 101 script_drawing_commands.Clear();
4762
4763 // zap out
4764
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 2424 times.
2525 for(int32_t i=1; i<=24; i++)
4765 {
4766 2424 draw_fuzzy(i);
4767 2424 advanceframe(true);
4768
4769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 if(Quit)
4770 {
4771 break;
4772 }
4773 2424 }
4774 101 }
4775
4776 101 void zapin()
4777 {
4778 101 FFCore.warpScriptCheck();
4779 101 draw_screen(tmpscr);
4780 101 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4781 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4782 101 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4783
4784 // zap out
4785 101 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4786
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 2424 times.
2525 for(int32_t i=24; i>=1; i--)
4787 {
4788 2424 draw_fuzzy(i);
4789 2424 advanceframe(true);
4790
4791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 if(Quit)
4792 {
4793 break;
4794 }
4795 2424 }
4796 101 }
4797
4798
4799 65 void wavyout(bool showhero)
4800 {
4801 65 draw_screen(tmpscr, showhero);
4802 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4803
4804 65 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4805 65 clear_to_color(wavebuf,0);
4806 65 blit(framebuf,wavebuf,0,0,16,0,256,224);
4807
4808 static PALETTE wavepal;
4809
4810 int32_t ofs;
4811 65 int32_t amplitude=8;
4812
4813 65 int32_t wavelength=4;
4814 65 double palpos=0, palstep=4, palstop=126;
4815
4816 65 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4817
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2730 times.
2795 for(int32_t i=0; i<168; i+=wavelength)
4818 {
4819
2/2
✓ Branch 0 taken 698880 times.
✓ Branch 1 taken 2730 times.
701610 for(int32_t l=0; l<256; l++)
4820 {
4821 698880 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(63-RAMpal[l].r))),0,63);
4822 698880 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(63-RAMpal[l].g))),0,63);
4823 698880 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(63-RAMpal[l].b))),0,63);
4824 698880 }
4825
4826 2730 palpos+=palstep;
4827
4828
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
2730 if(palpos>=0)
4829 {
4830 2730 hw_palette = &wavepal;
4831 2730 update_hw_pal = true;
4832 2730 }
4833 else
4834 {
4835 hw_palette = &RAMpal;
4836 update_hw_pal = true;
4837 }
4838
4839
2/2
✓ Branch 0 taken 458640 times.
✓ Branch 1 taken 2730 times.
461370 for(int32_t j=0; j+playing_field_offset<224; j++)
4840 {
4841
2/2
✓ Branch 0 taken 117411840 times.
✓ Branch 1 taken 458640 times.
117870480 for(int32_t k=0; k<256; k++)
4842 {
4843 117411840 ofs=0;
4844
4845
4/4
✓ Branch 0 taken 57308160 times.
✓ Branch 1 taken 60103680 times.
✓ Branch 2 taken 28654080 times.
✓ Branch 3 taken 28654080 times.
117411840 if((j<i)&&(j&1))
4846 {
4847 28654080 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4848 28654080 }
4849
4850 117411840 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4851 117411840 }
4852 458640 }
4853
4854 2730 advanceframe(true);
4855
4856 // animate_combos();
4857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2730 times.
2730 if(Quit)
4858 break;
4859 2730 }
4860
4861 65 destroy_bitmap(wavebuf);
4862 65 }
4863
4864 65 void wavyin()
4865 {
4866 65 draw_screen(tmpscr);
4867 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4868
4869 65 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4870 65 clear_to_color(wavebuf,0);
4871 65 blit(framebuf,wavebuf,0,0,16,0,256,224);
4872
4873 static PALETTE wavepal;
4874
4875 //Breaks dark rooms.
4876 //In any case I don't think we need this, since palette is already loaded in doWarp() (famous last words...) -DD
4877 /*
4878 loadfullpal();
4879 loadlvlpal(DMaps[currdmap].color);
4880 ringcolor(false);
4881 */
4882 65 refreshpal=false;
4883 int32_t ofs;
4884 65 int32_t amplitude=8;
4885 65 int32_t wavelength=4;
4886 65 double palpos=168, palstep=4, palstop=126;
4887
4888 65 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4889
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2730 times.
2795 for(int32_t i=0; i<168; i+=wavelength)
4890 {
4891
2/2
✓ Branch 0 taken 698880 times.
✓ Branch 1 taken 2730 times.
701610 for(int32_t l=0; l<256; l++)
4892 {
4893 698880 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(63-RAMpal[l].r))),0,63);
4894 698880 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(63-RAMpal[l].g))),0,63);
4895 698880 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(63-RAMpal[l].b))),0,63);
4896 698880 }
4897
4898 2730 palpos-=palstep;
4899
4900
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
2730 if(palpos>=0)
4901 {
4902 2730 hw_palette = &wavepal;
4903 2730 update_hw_pal = true;
4904 2730 }
4905 else
4906 {
4907 hw_palette = &RAMpal;
4908 update_hw_pal = true;
4909 }
4910
4911
2/2
✓ Branch 0 taken 458640 times.
✓ Branch 1 taken 2730 times.
461370 for(int32_t j=0; j+playing_field_offset<224; j++)
4912 {
4913
2/2
✓ Branch 0 taken 117411840 times.
✓ Branch 1 taken 458640 times.
117870480 for(int32_t k=0; k<256; k++)
4914 {
4915 117411840 ofs=0;
4916
4917
4/4
✓ Branch 0 taken 59404800 times.
✓ Branch 1 taken 58007040 times.
✓ Branch 2 taken 30051840 times.
✓ Branch 3 taken 29352960 times.
117411840 if((j<(167-i))&&(j&1))
4918 {
4919 29352960 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4920 29352960 }
4921
4922 117411840 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4923 117411840 }
4924 458640 }
4925
4926 2730 advanceframe(true);
4927 // animate_combos();
4928
4929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2730 times.
2730 if(Quit)
4930 break;
4931 2730 }
4932
4933 65 destroy_bitmap(wavebuf);
4934 65 }
4935
4936 2168 void blackscr(int32_t fcnt,bool showsubscr)
4937 {
4938 2168 reset_pal_cycling();
4939 2168 script_drawing_commands.Clear();
4940
4941 2168 FFCore.warpScriptCheck();
4942 2168 bool showtime = game->should_show_time();
4943
2/2
✓ Branch 0 taken 2168 times.
✓ Branch 1 taken 64970 times.
67138 while(fcnt>0)
4944 {
4945 64970 clear_bitmap(framebuf);
4946
4947
2/2
✓ Branch 0 taken 25080 times.
✓ Branch 1 taken 39890 times.
64970 if(showsubscr)
4948 {
4949 39890 put_passive_subscr(framebuf,0,passive_subscreen_offset,showtime,sspUP);
4950
3/4
✓ Branch 0 taken 39890 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 750 times.
✓ Branch 3 taken 39140 times.
39890 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4951 {
4952 750 do_script_draws(framebuf, tmpscr, 0, playing_field_offset);
4953 750 }
4954 39890 }
4955
4956 64970 advanceframe(true);
4957
4958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64970 times.
64970 if(Quit)
4959 break;
4960
4961 64970 --fcnt;
4962 }
4963 2168 }
4964
4965 1012 void openscreen(int32_t shape)
4966 {
4967 1012 reset_pal_cycling();
4968 1012 black_opening_count=0;
4969
4970
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 912 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100 times.
1012 if(COOLSCROLL || shape>-1)
4971 {
4972 912 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4973 912 return;
4974 }
4975 else
4976 {
4977 100 Hero.setDontDraw(true);
4978 100 show_subscreen_dmap_dots=false;
4979 100 show_subscreen_numbers=false;
4980 // show_subscreen_items=false;
4981 100 show_subscreen_life=false;
4982 }
4983
4984 100 int32_t x=128;
4985
4986 100 FFCore.warpScriptCheck();
4987
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 8000 times.
8100 for(int32_t i=0; i<80; i++)
4988 {
4989 8000 draw_screen(tmpscr);
4990 //? draw_screen already draws the subscreen -DD
4991 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4992 8000 x=128-(((i*128/80)/8)*8);
4993
4994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8000 times.
8000 if(x>0)
4995 {
4996 8000 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
4997 8000 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
4998 8000 }
4999
5000 8000 advanceframe(true);
5001
5002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8000 times.
8000 if(Quit)
5003 {
5004 break;
5005 }
5006 8000 }
5007
5008 100 Hero.setDontDraw(false);
5009 100 show_subscreen_items=true;
5010 100 show_subscreen_dmap_dots=true;
5011 1012 }
5012
5013 void closescreen(int32_t shape)
5014 {
5015 reset_pal_cycling();
5016 black_opening_count=0;
5017
5018 if(COOLSCROLL || shape>-1)
5019 {
5020 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
5021 return;
5022 }
5023 else
5024 {
5025 Hero.setDontDraw(true);
5026 show_subscreen_dmap_dots=false;
5027 show_subscreen_numbers=false;
5028 // show_subscreen_items=false;
5029 show_subscreen_life=false;
5030 }
5031
5032 int32_t x=128;
5033
5034 FFCore.warpScriptCheck();
5035 for(int32_t i=79; i>=0; --i)
5036 {
5037 draw_screen(tmpscr);
5038 //? draw_screen already draws the subscreen -DD
5039 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
5040 x=128-(((i*128/80)/8)*8);
5041
5042 if(x>0)
5043 {
5044 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
5045 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
5046 }
5047
5048 advanceframe(true);
5049
5050 if(Quit)
5051 {
5052 break;
5053 }
5054 }
5055
5056 Hero.setDontDraw(false);
5057 show_subscreen_items=true;
5058 show_subscreen_dmap_dots=true;
5059 }
5060
5061 179 int32_t TriforceCount()
5062 {
5063 179 int32_t c=0;
5064
5065
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 179 times.
1611 for(int32_t i=1; i<=8; i++)
5066
2/2
✓ Branch 0 taken 388 times.
✓ Branch 1 taken 1044 times.
2476 if(game->lvlitems[i]&liTRIFORCE)
5067 1044 ++c;
5068
5069 179 return c;
5070 }
5071
5072 int32_t onCustomGame()
5073 {
5074 int32_t file = getsaveslot();
5075
5076 if(file < 0)
5077 return D_O_K;
5078
5079 bool ret = (custom_game(file)!=0);
5080 return ret ? D_CLOSE : D_O_K;
5081 }
5082
5083 int32_t onContinue()
5084 {
5085 return D_CLOSE;
5086 }
5087
5088 int32_t onEsc() // Unused?? -L
5089 {
5090 return zc_getrawkey(KEY_ESC, true)?D_CLOSE:D_O_K;
5091 }
5092
5093 int32_t onVsync()
5094 {
5095 Throttlefps = !Throttlefps;
5096 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
5097 return D_O_K;
5098 }
5099
5100 int32_t onWinPosSave()
5101 {
5102 SaveWinPos = !SaveWinPos;
5103 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
5104 return D_O_K;
5105 }
5106 int32_t onIntegerScaling()
5107 {
5108 scaleForceInteger = !scaleForceInteger;
5109 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
5110 return D_O_K;
5111 }
5112 int32_t onStretchGame()
5113 {
5114 stretchGame = !stretchGame;
5115 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
5116 return D_O_K;
5117 }
5118
5119 int32_t onClickToFreeze()
5120 {
5121 ClickToFreeze = !ClickToFreeze;
5122 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
5123 return D_O_K;
5124 }
5125
5126 int32_t OnSaveZCConfig()
5127 {
5128 if(jwin_alert3(
5129 "Save Configuration",
5130 "Are you sure that you wish to save your present configuration settings?",
5131 "This will overwrite your prior settings!",
5132 NULL,
5133 "&Yes",
5134 "&No",
5135 NULL,
5136 'y',
5137 'n',
5138 0,
5139 get_zc_font(font_lfont)) == 1)
5140 {
5141 save_game_configs();
5142 return D_O_K;
5143 }
5144 else return D_O_K;
5145 }
5146
5147 int32_t OnnClearQuestDir()
5148 {
5149 auto current_path = fs::current_path() / "quests";
5150 if(jwin_alert3(
5151 "Clear Current Directory Cache",
5152 "Are you sure that you wish to reset where ZC Player looks for quests?",
5153 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
5154 NULL,
5155 "&Yes",
5156 "&No",
5157 NULL,
5158 'y',
5159 'n',
5160 0,
5161 get_zc_font(font_lfont)) == 1)
5162 {
5163 zc_set_config("zeldadx","quest_dir","quests");
5164 flush_config_file();
5165 strcpy(qstdir,"quests");
5166 #ifdef __EMSCRIPTEN__
5167 em_sync_fs();
5168 #endif
5169 return D_O_K;
5170 }
5171 else return D_O_K;
5172 }
5173
5174
5175 int32_t onConsoleZASM()
5176 {
5177 if ( !zasm_debugger )
5178 {
5179 AlertDialog("WARNING: ZASM Debugger",
5180 "Enabling this will open the ZASM Debugger Console"
5181 "\nThis will likely grind ZC to a halt with lag."
5182 "\nTo make any use of this, it is suggested that you read"
5183 "\nthe documentation for 'void Breakpoint(char[] string);'"
5184 " in 'ZScript_Additions.txt'"
5185 "\nThis is not recommended for normal users,"
5186 " and is only intended for ZC developers,"
5187 "\nor quest developers coding directly in ZASM"
5188 "\nAre you sure that you wish to open the ZASM Debugger?",
5189 [&](bool ret,bool)
5190 {
5191 if(ret)
5192 {
5193 FFCore.ZASMPrint(true);
5194 }
5195 }).show();
5196 return D_O_K;
5197 }
5198 else
5199 {
5200 FFCore.ZASMPrint(false);
5201 return D_O_K;
5202 }
5203 }
5204
5205
5206 int32_t onConsoleZScript()
5207 {
5208 if ( !zscript_debugger )
5209 {
5210 AlertDialog("ZScript Debugger",
5211 "Enabling this will open the ZScript Debugger Console"
5212 "\nThis will display any messages logged by scripts,"
5213 " including script errors."
5214 "\nAre you sure that you wish to open the ZScript Debugger?",
5215 [&](bool ret,bool)
5216 {
5217 if(ret)
5218 {
5219 FFCore.ZScriptConsole(true);
5220 }
5221 }).show();
5222 return D_O_K;
5223 }
5224 else
5225 {
5226 FFCore.ZScriptConsole(false);
5227 return D_O_K;
5228 }
5229 }
5230
5231 int32_t onClrConsoleOnReload()
5232 {
5233 clearConsoleOnReload = !clearConsoleOnReload;
5234 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5235 return D_O_K;
5236 }
5237 int32_t onClrConsoleOnLoad()
5238 {
5239 clearConsoleOnLoad = !clearConsoleOnLoad;
5240 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5241 return D_O_K;
5242 }
5243
5244
5245 int32_t onFrameSkip()
5246 {
5247 FrameSkip = !FrameSkip;
5248 return D_O_K;
5249 }
5250
5251 int32_t onSaveDragResize()
5252 {
5253 SaveDragResize = !SaveDragResize;
5254 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5255 return D_O_K;
5256 }
5257
5258 int32_t onDragAspect()
5259 {
5260 DragAspect = !DragAspect;
5261 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5262 return D_O_K;
5263 }
5264
5265 int32_t onTransLayers()
5266 {
5267 TransLayers = !TransLayers;
5268 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5269 return D_O_K;
5270 }
5271
5272 int32_t onNESquit()
5273 {
5274 NESquit = !NESquit;
5275 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5276 return D_O_K;
5277 }
5278
5279 int32_t onVolKeys()
5280 {
5281 volkeys = !volkeys;
5282 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5283 return D_O_K;
5284 }
5285
5286 int32_t onShowFPS()
5287 {
5288 ShowFPS = !ShowFPS;
5289 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5290 return D_O_K;
5291 }
5292
5293 1095768060 bool is_Fkey(int32_t k)
5294 {
5295
2/2
✓ Branch 0 taken 111434040 times.
✓ Branch 1 taken 984334020 times.
1095768060 switch(k)
5296 {
5297 case KEY_F1:
5298 case KEY_F2:
5299 case KEY_F3:
5300 case KEY_F4:
5301 case KEY_F5:
5302 case KEY_F6:
5303 case KEY_F7:
5304 case KEY_F8:
5305 case KEY_F9:
5306 case KEY_F10:
5307 case KEY_F11:
5308 case KEY_F12:
5309 111434040 return true;
5310 }
5311
5312 984334020 return false;
5313 1095768060 }
5314
5315 void kb_getkey(DIALOG *d);
5316
5317 //Used by all keyboard key settings dialogues.
5318 void kb_clearjoystick(DIALOG *d)
5319 {
5320 d->flags|=D_SELECTED;
5321
5322 jwin_button_proc(MSG_DRAW,d,0);
5323 jwin_draw_win(gui_bmp, (gui_bmp->w-160)/2, (gui_bmp->h-48)/2, 168, 48, FR_WIN);
5324 // text_mode(vc(11));
5325 textout_centre_ex(gui_bmp, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5326 textout_centre_ex(gui_bmp, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5327
5328 update_hw_screen(true);
5329
5330 clear_keybuf();
5331 int32_t k = next_press_key();
5332 clear_keybuf();
5333
5334 //shnarf
5335 //47=f1
5336 //59=esc
5337 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5338 // *((int32_t*)d->dp3) = k;
5339 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5340
5341
5342 d->flags&=~D_SELECTED;
5343 }
5344
5345 //Clears key to 0.
5346 //Used by all keyboard key settings dialogues.
5347 void kb_clearkey(DIALOG *d);
5348
5349 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5350 {
5351 switch(msg)
5352 {
5353 case MSG_KEY:
5354 case MSG_CLICK:
5355
5356 kb_clearjoystick(d);
5357
5358 while(gui_mouse_b())
5359 {
5360 clear_keybuf();
5361 rest(1);
5362 }
5363
5364 return D_REDRAW;
5365 }
5366
5367 return jwin_button_proc(msg,d,c);
5368 }
5369
5370 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5371 //Only used in keyboard settings dialogues to clear keys.
5372 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5373
5374 int32_t j_getbtn(DIALOG *d)
5375 {
5376 d->flags|=D_SELECTED;
5377 jwin_button_proc(MSG_DRAW,d,0);
5378 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5379 // text_mode(vc(11));
5380 int32_t y = screen->h/2 - 12;
5381 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5382 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5383 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5384
5385 update_hw_screen(true);
5386
5387 int32_t b = next_joy_input(true);
5388 if (b == -2)
5389 return D_CLOSE;
5390
5391 if(b>=0)
5392 *((int32_t*)d->dp3) = b;
5393
5394 d->flags&=~D_SELECTED;
5395
5396 if (player)
5397 player->joy_on = TRUE;
5398
5399 return D_O_K;
5400 }
5401
5402 void j_getstick(DIALOG *d)
5403 {
5404 d->flags|=D_SELECTED;
5405 jwin_button_proc(MSG_DRAW,d,0);
5406 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5407 // text_mode(vc(11));
5408 int32_t y = screen->h/2 - 12;
5409 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5410 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5411 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5412
5413 update_hw_screen(true);
5414
5415 int32_t b = next_joy_input(false);
5416
5417 if(b>=0)
5418 *((int32_t*)d->dp3) = b;
5419
5420 d->flags&=~D_SELECTED;
5421
5422 if (player)
5423 player->joy_on = TRUE;
5424 }
5425
5426 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5427 {
5428 switch(msg)
5429 {
5430 case MSG_KEY:
5431 case MSG_CLICK:
5432
5433 int ret = j_getbtn(d);
5434 if (ret != D_O_K)
5435 return ret;
5436
5437 while(gui_mouse_b()) {
5438 rest(1);
5439 clear_keybuf();
5440 }
5441
5442 return D_REDRAW;
5443 }
5444
5445 return jwin_button_proc(msg,d,c);
5446 }
5447
5448 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5449 {
5450 switch(msg)
5451 {
5452 case MSG_KEY:
5453 case MSG_CLICK:
5454
5455 j_getstick(d);
5456
5457 while(gui_mouse_b()) {
5458 rest(1);
5459 clear_keybuf();
5460 }
5461
5462 return D_REDRAW;
5463 }
5464
5465 return jwin_button_proc(msg,d,c);
5466 }
5467
5468 //shnarf
5469 extern const char *key_str[];
5470 std::string get_keystr(int key);
5471
5472 const char *pan_str[4] = { "MONO", " 1/2", " 3/4", "FULL" };
5473 //extern int32_t zcmusic_bufsz;
5474
5475 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5476 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5477 str_primary_stick[80], str_secondary_stick[80];
5478
5479 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5480 {
5481 //these are here to bypass compiler warnings about unused arguments
5482 c=c;
5483
5484 if (d->w == 1)
5485 {
5486 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5487 {
5488 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5489 return D_CLOSE;
5490 }
5491 }
5492
5493 if(msg==MSG_DRAW)
5494 {
5495 switch(d->w)
5496 {
5497 case 0:
5498 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5499 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5500 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5501 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5502 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5503 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5504 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5505 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5506 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5507 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5508 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5509 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5510 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5511 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5512 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5513 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5514 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5515 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5516 break;
5517
5518 case 1:
5519 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5520 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5521 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5522 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5523 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5524 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5525 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5526 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5527 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5528 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5529 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5530 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5531 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5532 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5533 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5534 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5535 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5536 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5537 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5538 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5539 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5540 break;
5541
5542 case 2:
5543 sprintf(str_a," %3d",midi_volume);
5544 sprintf(str_b," %3d",digi_volume);
5545 sprintf(str_l," %3d",emusic_volume);
5546 sprintf(str_m," %3dKB",zcmusic_bufsz);
5547 sprintf(str_r," %3d",sfx_volume);
5548 strcpy(str_s,pan_str[pan_style]);
5549 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5550 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5551 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5552 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5553 break;
5554 }
5555 }
5556
5557 return D_O_K;
5558 }
5559
5560 int32_t set_vol(void *dp3, int32_t d2)
5561 {
5562 switch(((int32_t*)dp3)[0])
5563 {
5564 case 0:
5565 midi_volume = zc_min(d2<<3,255);
5566 break;
5567
5568 case 1:
5569 digi_volume = zc_min(d2<<3,255);
5570 break;
5571
5572 case 2:
5573 emusic_volume = zc_min(d2<<3,255);
5574 break;
5575
5576 case 3:
5577 sfx_volume = zc_min(d2<<3,255);
5578 break;
5579 }
5580
5581 // text_mode(vc(11));
5582 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%3d",zc_min(d2<<3,255));
5583 return D_O_K;
5584 }
5585
5586 int32_t set_pan(void *dp3, int32_t d2)
5587 {
5588 pan_style = vbound(d2,0,3);
5589 // text_mode(vc(11));
5590 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5591 return D_O_K;
5592 }
5593
5594 int32_t set_buf(void *dp3, int32_t d2)
5595 {
5596 // text_mode(vc(11));
5597 zcmusic_bufsz = d2 + 1;
5598 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%3dKB",zcmusic_bufsz);
5599 return D_O_K;
5600 }
5601
5602 static int32_t gamepad_joys_list[] =
5603 {
5604 61,
5605 -1
5606 };
5607
5608 static int32_t gamepad_btn_list[] =
5609 {
5610 6,
5611 7,8,9,10,11,12,13,14,15,16,17,
5612 18,19,20,21,22,23,24,25,26,27,28,
5613 29,30,31,32,33,34,35,36,37,38,39,
5614 -1
5615 };
5616
5617 static int32_t gamepad_dirs_list[] =
5618 {
5619 40,41,42,43,
5620 44,45,46,47,
5621 48,49,50,51,
5622 52,53,54,55,
5623 56,57,58,59,
5624 60,
5625 -1
5626 };
5627
5628 static TABPANEL gamepad_tabs[] =
5629 {
5630 // (text)
5631 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5632 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5633 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5634 { NULL, 0, NULL, 0, NULL }
5635 };
5636
5637 const char *joy_list(int32_t index, int32_t *list_size)
5638 {
5639 if (index == -1)
5640 {
5641 *list_size = al_get_num_joysticks();
5642 return NULL;
5643 }
5644
5645 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5646 if (!joy)
5647 {
5648 return "?";
5649 }
5650
5651 return al_get_joystick_name(joy);
5652 }
5653
5654 116 static ListData joy__list(joy_list, &font);
5655
5656 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5657 {
5658 int32_t d2 = d->d2;
5659 int32_t ret = jwin_droplist_proc(msg,d,c);
5660
5661 if(d2!=d->d2)
5662 {
5663 joystick_index = d->d2;
5664 ret |= D_REDRAW_ALL;
5665 }
5666
5667 return ret;
5668 }
5669
5670 static DIALOG gamepad_dlg[] =
5671 {
5672 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5673 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5674 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5675 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5676 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5677 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5678 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5679 // 6
5680 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5681 // 7
5682 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5683 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5684 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5685 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5686 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5687 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5688 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5689 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5690 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5691 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5692 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5693 // 18
5694 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5695 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5696 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5697 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5698 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5699 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5700 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5701 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5702 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5703 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5704 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5705 // 29
5706 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5707 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5708 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5709 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5710 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5711 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5712 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5713 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5714 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5715 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5716 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5717 // 40
5718 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5719 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5720 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5721 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5722 // 44
5723 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5724 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5725 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5726 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5727 // 48
5728 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5729 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5730 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5731 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5732 // 52
5733 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5734 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5735 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5736 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5737 // 56
5738 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5739 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5740 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5741 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5742 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5743
5744 // 61
5745 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5746
5747 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5748 };
5749
5750 static int32_t keyboard_keys_list[] =
5751 {
5752 6,7,8,9,10,
5753 11,12,13,14,15,16,17,18,19,20,
5754 21,22,23,24,25,26,27,28,29,30,
5755 31,32,33,34,35,36,37,38,39,40,
5756 -1
5757 };
5758
5759 static int32_t keyboard_dirs_list[] =
5760 {
5761 41,42,43,44,
5762 45,46,47,48,
5763 49,50,51,52,
5764 53,54,55,56,
5765 -1
5766 };
5767
5768 static int32_t keyboard_mods_list[] =
5769 {
5770 57,58,59,60,
5771 61,62,63,64,
5772 65,66,67,68,
5773 69,70,71,72,
5774 -1
5775 };
5776
5777 static TABPANEL keyboard_control_tabs[] =
5778 {
5779 // (text)
5780 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5781 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5782 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5783 { NULL, 0, NULL, 0, NULL }
5784 };
5785
5786 static DIALOG keyboard_control_dlg[] =
5787 {
5788 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5789 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5790 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5791 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5792 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5793 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5794 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5795 // Keys
5796 // 6
5797 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5798 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5799 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5800 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5801 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5802 // 11
5803 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5804 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5805 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5806 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5807 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5808 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5809 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5810 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5811 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5812 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5813 // 21
5814 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5815 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5816 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5817 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5818 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5819 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5820 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5821 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5822 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5823 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5824 // 31
5825 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5826 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5827 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5828 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5829 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5830 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5831 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5832 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5833 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5834 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5835 // Dirs
5836 // 41
5837 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5838 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5839 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5840 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5841 // 45
5842 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5843 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5844 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5845 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5846 // 49
5847 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5848 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5849 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5850 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5851 // 53
5852 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5853 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5854 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5855 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5856 // Mods
5857 // 57
5858 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5859 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5860 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5861 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5862 // 61
5863 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5864 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5865 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5866 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5867 // 65
5868 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5869 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5870 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5871 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5872 // 69
5873 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5874 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5875 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5876 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5877 // 73
5878 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5879 };
5880
5881 /*
5882 int32_t midi_dp[3] = {0,147,104};
5883 int32_t digi_dp[3] = {1,147,120};
5884 int32_t pan_dp[3] = {0,147,136};
5885 int32_t buf_dp[3] = {0,147,152};
5886 */
5887 int32_t midi_dp[3] = {0,0,0};
5888 int32_t digi_dp[3] = {1,0,0};
5889 int32_t emus_dp[3] = {2,0,0};
5890 int32_t buf_dp[3] = {0,0,0};
5891 int32_t sfx_dp[3] = {3,0,0};
5892 int32_t pan_dp[3] = {0,0,0};
5893
5894 static DIALOG sound_dlg[] =
5895 {
5896 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5897 116 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5898 116 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5899 116 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5900 116 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5901 116 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5902 116 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5903 116 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5904 116 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_b, NULL, NULL },
5905 116 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5906 116 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_m, NULL, NULL },
5907 // 10
5908 116 { jwin_rtext_proc, 190, 104, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5909 116 { jwin_rtext_proc, 190, 120, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5910 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5911 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5912 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5913 116 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5914 116 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, digi_dp },
5915 116 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5916 116 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 127, 0, NULL, (void *) set_buf, buf_dp },
5917 116 { jwin_slider_proc, 196, 104, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5918 //20
5919 116 { jwin_slider_proc, 196, 120, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5920 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5921 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5922 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5923 116 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Master MIDI Volume", NULL, NULL },
5924 116 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Master Digi Volume", NULL, NULL },
5925 116 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Enhanced Music Volume", NULL, NULL },
5926 116 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Enhanced Music Buffer", NULL, NULL },
5927 116 { jwin_text_proc, 17, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5928 116 { jwin_text_proc, 17, 120, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5929 //30
5930 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5931 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5932 116 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5933 116 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5934 };
5935
5936 char zc_builddate[80];
5937 char zc_aboutstr[80];
5938
5939 static DIALOG about_dlg[] =
5940 {
5941 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5942 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5943 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5944 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5945 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5946 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5947 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5948 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5949 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5950 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5951 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5952 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5953 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5954 };
5955
5956
5957 static DIALOG quest_dlg[] =
5958 {
5959 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5960 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5961 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5962 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5963 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5964 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5965 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5966 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5967 { jwin_text_proc, 184, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5968 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5969 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5970 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5971 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5972 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5973 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5974 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5975 };
5976
5977 static DIALOG triforce_dlg[] =
5978 {
5979 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5980 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5981 // 1
5982 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5983 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5984 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5985 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5986 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5987 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5988 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5989 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5990 // 9
5991 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5992 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5993 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5994 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5995 };
5996
5997 bool zc_getname(const char *prompt,const char *ext,EXT_LIST *list,const char *def,bool usefilename)
5998 {
5999 go();
6000 int32_t ret=0;
6001 ret = zc_getname_nogo(prompt,ext,list,def,usefilename);
6002 comeback();
6003 return ret != 0;
6004 }
6005
6006
6007 bool zc_getname_nogo(const char *prompt,const char *ext,EXT_LIST *list,const char *def,bool usefilename)
6008 {
6009 if(def!=modulepath)
6010 strcpy(modulepath,def);
6011
6012 if(!usefilename)
6013 {
6014 int32_t i=(int32_t)strlen(modulepath);
6015
6016 while(i>=0 && modulepath[i]!='\\' && modulepath[i]!='/')
6017 modulepath[i--]=0;
6018 }
6019
6020 // int32_t ret = file_select_ex(prompt,modulepath,ext,255,-1,-1);
6021 int32_t ret=0;
6022 int32_t sel=0;
6023
6024 if(list==NULL)
6025 {
6026 ret = jwin_file_select_ex(prompt,modulepath,ext,2048,-1,-1,get_zc_font(font_lfont));
6027 }
6028 else
6029 {
6030 ret = jwin_file_browse_ex(prompt, modulepath, list, &sel, 2048, -1, -1, get_zc_font(font_lfont));
6031 }
6032
6033 return ret!=0;
6034 }
6035
6036 int32_t onToggleRecordingNewSaves()
6037 {
6038 if (zc_get_config("zeldadx", "replay_new_saves", false))
6039 {
6040 zc_set_config("zeldadx", "replay_new_saves", false);
6041 }
6042 else
6043 {
6044 zc_set_config("zeldadx", "replay_new_saves", true);
6045 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
6046 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6047 }
6048 return D_O_K;
6049 }
6050
6051 int32_t onToggleSnapshotAllFrames()
6052 {
6053 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
6054 return D_O_K;
6055 }
6056
6057 int32_t onStopReplayOrRecord()
6058 {
6059 if (replay_is_replaying())
6060 {
6061 replay_quit();
6062 }
6063 else if (replay_get_mode() == ReplayMode::Record)
6064 {
6065 if (!replay_get_meta_bool("test_mode"))
6066 {
6067 jwin_alert("Recording", "You cannot stop recording a save file.",
6068 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6069 return D_CLOSE;
6070 }
6071
6072 if (jwin_alert("Stop Recording",
6073 "Save replay to disk and stop recording?",
6074 "This will stop the recording.",
6075 NULL,
6076 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6077 return D_CLOSE;
6078
6079 replay_save();
6080 replay_stop();
6081 }
6082 return D_O_K;
6083 }
6084
6085 static int32_t handle_on_load_replay(ReplayMode mode)
6086 {
6087 if (Playing)
6088 {
6089 if (jwin_alert("Replay - Warning!",
6090 "Loading a replay will exit the current game.",
6091 "All unsaved progress will be lost.",
6092 "Do you wish to continue?",
6093 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6094 return D_CLOSE;
6095 }
6096
6097 std::string mode_string = replay_mode_to_string(mode);
6098 mode_string[0] = std::toupper(mode_string[0]);
6099
6100 std::string line_1 = "Select a replay file to play back.";
6101 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
6102 std::string line_3 = "You can stop the replay and take over manually any time.";
6103 if (mode == ReplayMode::Update)
6104 {
6105 line_1 = "Select a replay file to update.";
6106 line_2 = "WARNING: be sure to back up the zplay file";
6107 line_3 = "and verify that the updated replay works as expected!";
6108 }
6109
6110 if (jwin_alert(mode_string.c_str(),
6111 line_1.c_str(),
6112 line_2.c_str(),
6113 line_3.c_str(),
6114 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
6115 {
6116 char replay_path[2048];
6117 strcpy(replay_path, "replays/");
6118 if (jwin_file_select_ex(
6119 fmt::format("Load Replay ({})", REPLAY_EXTENSION).c_str(),
6120 replay_path, REPLAY_EXTENSION.c_str(), 2048, -1, -1, get_zc_font(font_lfont)) == 0)
6121 return D_CLOSE;
6122
6123 replay_quit();
6124 load_replay_file_deferred(mode, replay_path);
6125 Quit = qRESET;
6126 return D_CLOSE;
6127 }
6128 return D_O_K;
6129 }
6130
6131 int32_t onLoadReplay()
6132 {
6133 return handle_on_load_replay(ReplayMode::Replay);
6134 }
6135
6136 int32_t onLoadReplayAssert()
6137 {
6138 return handle_on_load_replay(ReplayMode::Assert);
6139 }
6140
6141 int32_t onLoadReplayUpdate()
6142 {
6143 return handle_on_load_replay(ReplayMode::Update);
6144 }
6145
6146 int32_t onSaveReplay()
6147 {
6148 if (replay_get_mode() == ReplayMode::Record)
6149 {
6150 if (!replay_get_meta_bool("test_mode"))
6151 {
6152 if (jwin_alert("Save Replay",
6153 "This will save a copy of the replay up to this point.",
6154 "The official replay file will be untouched.",
6155 "Do you wish to continue?",
6156 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6157 return D_CLOSE;
6158
6159 char replay_path[2048];
6160 strcpy(replay_path, replay_get_replay_path().string().c_str());
6161 if (jwin_file_select_ex(
6162 fmt::format("Save Replay ({})", REPLAY_EXTENSION).c_str(),
6163 replay_path, REPLAY_EXTENSION.c_str(), 2048, -1, -1, get_zc_font(font_lfont)) == 0)
6164 return D_CLOSE;
6165
6166 if (fileexists(replay_path))
6167 {
6168 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
6169 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6170 return D_CLOSE;
6171 }
6172
6173 replay_save(replay_path);
6174 }
6175 else
6176 {
6177 replay_save();
6178 }
6179 }
6180 return D_O_K;
6181 }
6182
6183 static MENU replay_menu[] =
6184 {
6185 { (char *)"Record new saves", onToggleRecordingNewSaves, NULL, 0, NULL },
6186 { (char *)"Stop replay", onStopReplayOrRecord, NULL, 0, NULL },
6187 { (char *)"Load replay", onLoadReplay, NULL, 0, NULL },
6188 { (char *)"Load replay (assert)", onLoadReplayAssert, NULL, 0, NULL },
6189 { (char *)"Load replay (update)", onLoadReplayUpdate, NULL, 0, NULL },
6190 { (char *)"Save replay", onSaveReplay, NULL, 0, NULL },
6191 { (char *)"Enable snapshot all frames", onToggleSnapshotAllFrames,NULL, 0, NULL },
6192
6193 { NULL, NULL, NULL, 0, NULL }
6194 };
6195
6196 static DIALOG credits_dlg[] =
6197 {
6198 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6199 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6200 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6201 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6202 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6203 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6204 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6205 };
6206
6207 116 static ListData dmap_list(dmaplist, &font);
6208
6209 static DIALOG goto_dlg[] =
6210 {
6211 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6212 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6213 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6214 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6215 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6216 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6217 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6218 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6219 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6220 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6221 };
6222
6223 int32_t onGoTo()
6224 {
6225 bool music = false;
6226 music = music;
6227 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6228
6229 goto_dlg[0].dp2=get_zc_font(font_lfont);
6230 goto_dlg[4].d2=cheat_goto_dmap;
6231 goto_dlg[6].dp=cheat_goto_screen_str;
6232
6233 clear_keybuf();
6234
6235 large_dialog(goto_dlg);
6236
6237 if(do_zqdialog(goto_dlg,4)==1)
6238 {
6239 // dmap, screen
6240 cheats_enqueue(Cheat::GoTo, goto_dlg[4].d2, zc_min(zc_xtoi(cheat_goto_screen_str),0x7F));
6241 };
6242
6243 return D_O_K;
6244 }
6245
6246 int32_t onGoToComplete()
6247 {
6248 if(!Playing)
6249 {
6250 return D_O_K;
6251 }
6252
6253 enter_sys_pal();
6254 music_pause();
6255 pause_all_sfx();
6256 onGoTo();
6257 eat_buttons();
6258
6259 zc_readrawkey(KEY_ESC);
6260
6261 exit_sys_pal();
6262 music_resume();
6263 resume_all_sfx();
6264 return D_O_K;
6265 }
6266
6267 int32_t onCredits()
6268 {
6269 return D_O_K;
6270 }
6271
6272 const char *midilist(int32_t index, int32_t *list_size)
6273 {
6274 if(index<0)
6275 {
6276 *list_size=0;
6277
6278 for(int32_t i=0; i<MAXMIDIS; i++)
6279 if(tunes[i].data)
6280 ++(*list_size);
6281
6282 return NULL;
6283 }
6284
6285 int32_t i=0,m=0;
6286
6287 while(m<=index && i<=MAXMIDIS)
6288 {
6289 if(tunes[i].data)
6290 ++m;
6291
6292 ++i;
6293 }
6294
6295 --i;
6296
6297 if(i==MAXMIDIS && m<index)
6298 return "(null)";
6299
6300 return tunes[i].title;
6301 }
6302
6303 /* ------- MIDI info stuff -------- */
6304
6305 char *text;
6306 midi_info *zmi;
6307 bool dialog_running;
6308 bool listening;
6309
6310 void get_info(int32_t index);
6311
6312 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6313 {
6314 int32_t d2 = d->d2;
6315 int32_t ret = jwin_droplist_proc(msg,d,c);
6316
6317 if(d2!=d->d2)
6318 {
6319 get_info(d->d2);
6320 }
6321
6322 return ret;
6323 }
6324
6325 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6326 {
6327 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6328
6329 int32_t ret = jwin_button_proc(msg,d,c);
6330
6331 if(ret == D_CLOSE)
6332 {
6333 // get current midi index
6334 int32_t index = (d+(d->d1))->d2;
6335 int32_t i=0, m=0;
6336
6337 while(m<=index && i<=MAXMIDIS)
6338 {
6339 if(tunes[i].data)
6340 ++m;
6341
6342 ++i;
6343 }
6344
6345 --i;
6346 jukebox(i);
6347 listening = true;
6348 ret = D_O_K;
6349 }
6350
6351 return ret;
6352 }
6353
6354 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6355 {
6356 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6357
6358 int32_t ret = jwin_button_proc(msg,d,c);
6359
6360 if(ret == D_CLOSE)
6361 {
6362 // get current midi index
6363 int32_t index = (d+(d->d1))->d2;
6364 int32_t i=0, m=0;
6365
6366 while(m<=index && i<=MAXMIDIS)
6367 {
6368 if(tunes[i].data)
6369 ++m;
6370
6371 ++i;
6372 }
6373
6374 --i;
6375
6376 // get file name
6377
6378 int32_t sel=0;
6379 //struct ffblk f;
6380 char title[40] = "Save MIDI: ";
6381 char fname[2048];
6382 memset(fname,0,2048);
6383 static EXT_LIST list[] =
6384 {
6385 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6386 { (char *)"HTML files (*.html, *.html)", (char *)"htm html" },
6387 { NULL, NULL }
6388 };
6389
6390 strcpy(title+11, tunes[i].title);
6391 title[39] = '\0';
6392
6393 if(jwin_file_browse_ex(title, fname, list, &sel, 2048, -1, -1, get_zc_font(font_lfont))==0)
6394 goto done;
6395
6396 if(exists(fname))
6397 {
6398 if(jwin_alert(title, fname, "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6399 goto done;
6400 }
6401
6402 // save midi i
6403
6404 if(save_midi(fname, (MIDI*)tunes[i].data) != 0)
6405 jwin_alert(title, "Error saving MIDI to", fname, NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6406
6407 done:
6408 chop_path(fname);
6409 ret = D_REDRAW;
6410 }
6411
6412 return ret;
6413 }
6414
6415 116 static ListData midi_list(midilist, &font);
6416
6417 static DIALOG midi_dlg[] =
6418 {
6419 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6420 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6421 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6422 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6423 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6424 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6425 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6426 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6427 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6428 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6429 };
6430
6431 void get_info(int32_t index)
6432 {
6433 int32_t i=0, m=0;
6434
6435 while(m<=index && i<=MAXMIDIS)
6436 {
6437 if(tunes[i].data)
6438 ++m;
6439
6440 ++i;
6441 }
6442
6443 --i;
6444
6445 if(i==MAXMIDIS && m<index)
6446 strcpy(text,"(null)");
6447 else
6448 {
6449 get_midi_info((MIDI*)tunes[i].data,zmi);
6450 get_midi_text((MIDI*)tunes[i].data,zmi,text);
6451 }
6452
6453 midi_dlg[0].dp2=get_zc_font(font_lfont);
6454 midi_dlg[3].dp = text;
6455 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6456 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6457
6458 if(dialog_running)
6459 {
6460 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6461 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6462 }
6463 }
6464
6465 int32_t onMIDICredits()
6466 {
6467 text = (char*)malloc(4096);
6468 zmi = (midi_info*)malloc(sizeof(midi_info));
6469
6470 if(!text || !zmi)
6471 {
6472 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6473 return D_O_K;
6474 }
6475
6476 bool do_pause_midi = midi_pos >= 0 && currmidi;
6477 auto restore_midi = currmidi;
6478 if(do_pause_midi)
6479 {
6480 paused_midi_pos = midi_pos;
6481 stop_midi();
6482 midi_suspended = midissuspHALTED;
6483 }
6484
6485 midi_dlg[0].dp2=get_zc_font(font_lfont);
6486 midi_dlg[2].d1 = 0;
6487 midi_dlg[2].d2 = 0;
6488 midi_dlg[4].flags = D_EXIT;
6489 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6490
6491 listening = false;
6492 dialog_running=false;
6493 get_info(0);
6494
6495 dialog_running=true;
6496
6497 large_dialog(midi_dlg);
6498
6499 do_zqdialog(midi_dlg,0);
6500 dialog_running=false;
6501
6502 if(listening)
6503 music_stop();
6504
6505 if(do_pause_midi)
6506 {
6507 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6508 midi_suspended = midissuspRESUME;
6509 currmidi = restore_midi;
6510 midi_pos = paused_midi_pos;
6511 }
6512
6513 if(text) free(text);
6514 if(zmi) free(zmi);
6515 return D_O_K;
6516 }
6517
6518 int32_t onAbout()
6519 {
6520 char buf1[80]={0};
6521 std::ostringstream oss;
6522 sprintf(buf1,"%s, Version: %s", ZC_PLAYER_NAME,ZC_PLAYER_V);
6523 oss << buf1 << '\n';
6524 sprintf(buf1, "%s", ALPHA_VER_STR);
6525 oss << buf1 << '\n';
6526 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6527 oss << buf1 << '\n';
6528 sprintf(buf1, "Built By: %s", DEV_SIGNOFF);
6529 oss << buf1 << '\n';
6530 sprintf(buf1, "Tag: %s", getReleaseTag());
6531 oss << buf1 << '\n';
6532
6533 InfoDialog("About ZC", oss.str()).show();
6534 return D_O_K;
6535 }
6536
6537 int32_t onQuest()
6538 {
6539 char fname[100];
6540 strcpy(fname, get_filename(qstpath));
6541 quest_dlg[0].dp2=get_zc_font(font_lfont);
6542 quest_dlg[1].dp = fname;
6543
6544 if(QHeader.quest_number==0)
6545 sprintf(str_a,"Custom");
6546 else
6547 sprintf(str_a,"%d",QHeader.quest_number);
6548
6549 sprintf(str_s,"%s",VerStr(QHeader.zelda_version));
6550
6551 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6552 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6553
6554 large_dialog(quest_dlg);
6555
6556 do_zqdialog(quest_dlg, 0);
6557 return D_O_K;
6558 }
6559
6560 void call_vidmode_dlg();
6561 int32_t onVidMode()
6562 {
6563 call_vidmode_dlg();
6564 return D_O_K;
6565 }
6566
6567 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6568 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6569 //Added an extra statement, so that if the key is cleared to 0, the cleared
6570 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6571
6572 void load_ukeys(int32_t* arr)
6573 {
6574 arr[ukey_a] = Akey;
6575 arr[ukey_b] = Bkey;
6576 arr[ukey_s] = Skey;
6577 arr[ukey_l] = Lkey;
6578 arr[ukey_r] = Rkey;
6579 arr[ukey_p] = Pkey;
6580 arr[ukey_ex1] = Exkey1;
6581 arr[ukey_ex2] = Exkey2;
6582 arr[ukey_ex3] = Exkey3;
6583 arr[ukey_ex4] = Exkey4;
6584 arr[ukey_du] = DUkey;
6585 arr[ukey_dd] = DDkey;
6586 arr[ukey_dl] = DLkey;
6587 arr[ukey_dr] = DRkey;
6588 arr[ukey_mod1a] = cheat_modifier_keys[0];
6589 arr[ukey_mod1b] = cheat_modifier_keys[1];
6590 arr[ukey_mod2a] = cheat_modifier_keys[2];
6591 arr[ukey_mod2b] = cheat_modifier_keys[3];
6592 };
6593
6594 static const char* ukey_names[] = {
6595 "A", "B", "Start", "L", "R", "Map",
6596 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6597 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6598 "Cheat Mod R1", "Cheat Mod R2",
6599 };
6600 std::string get_ukey_name(int32_t k)
6601 {
6602 if (k < num_ukey) return ukey_names[k];
6603 return "";
6604 }
6605
6606 int32_t onKeyboard()
6607 {
6608 int32_t a = Akey;
6609 int32_t b = Bkey;
6610 int32_t s = Skey;
6611 int32_t l = Lkey;
6612 int32_t r = Rkey;
6613 int32_t p = Pkey;
6614 int32_t ex1 = Exkey1;
6615 int32_t ex2 = Exkey2;
6616 int32_t ex3 = Exkey3;
6617 int32_t ex4 = Exkey4;
6618 int32_t du = DUkey;
6619 int32_t dd = DDkey;
6620 int32_t dl = DLkey;
6621 int32_t dr = DRkey;
6622 int32_t mod1a = cheat_modifier_keys[0];
6623 int32_t mod1b = cheat_modifier_keys[1];
6624 int32_t mod2a = cheat_modifier_keys[2];
6625 int32_t mod2b = cheat_modifier_keys[3];
6626 bool done=false;
6627 int32_t ret;
6628
6629 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6630
6631 large_dialog(keyboard_control_dlg);
6632
6633 while(!done)
6634 {
6635 ret = do_zqdialog(keyboard_control_dlg,3);
6636
6637 if(ret==3) // OK
6638 {
6639 int32_t ukeys[num_ukey];
6640 load_ukeys(ukeys);
6641 std::vector<std::string> uniqueError;
6642 for(int32_t q = 0; q < num_ukey; ++q)
6643 {
6644 for(int32_t p = q+1; p < num_ukey; ++p)
6645 {
6646 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6647 {
6648 char buf[64];
6649 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6650 std::string str(buf);
6651 uniqueError.push_back(str);
6652 }
6653 }
6654 }
6655 if(uniqueError.size() == 0)
6656 {
6657 done = true;
6658 save_control_configs(true);
6659 }
6660 else
6661 {
6662 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6663 box_out("Cannot have duplicate keybinds!"); box_eol();
6664 for(std::vector<std::string>::iterator it = uniqueError.begin();
6665 it != uniqueError.end(); ++it)
6666 {
6667 box_out((*it).c_str()); box_eol();
6668 }
6669 box_end(true);
6670 }
6671 }
6672 else // Cancel
6673 {
6674 Akey = a;
6675 Bkey = b;
6676 Skey = s;
6677 Lkey = l;
6678 Rkey = r;
6679 Pkey = p;
6680 Exkey1 = ex1;
6681 Exkey2 = ex2;
6682 Exkey3 = ex3;
6683 Exkey4 = ex4;
6684 DUkey = du;
6685 DDkey = dd;
6686 DLkey = dl;
6687 DRkey = dr;
6688 cheat_modifier_keys[0] = mod1a;
6689 cheat_modifier_keys[1] = mod1b;
6690 cheat_modifier_keys[2] = mod2a;
6691 cheat_modifier_keys[3] = mod2b;
6692
6693 done=true;
6694 }
6695
6696 rest(1);
6697 }
6698
6699 return D_O_K;
6700 }
6701
6702 int32_t onGamepad()
6703 {
6704 if (al_get_num_joysticks() == 0)
6705 {
6706 InfoDialog("ZC", "No gamepads detected.").show();
6707 return D_O_K;
6708 }
6709
6710 int32_t a = Abtn;
6711 int32_t b = Bbtn;
6712 int32_t s = Sbtn;
6713 int32_t l = Lbtn;
6714 int32_t r = Rbtn;
6715 int32_t m = Mbtn;
6716 int32_t p = Pbtn;
6717 int32_t ex1 = Exbtn1;
6718 int32_t ex2 = Exbtn2;
6719 int32_t ex3 = Exbtn3;
6720 int32_t ex4 = Exbtn4;
6721 int32_t up = DUbtn;
6722 int32_t down = DDbtn;
6723 int32_t left = DLbtn;
6724 int32_t right = DRbtn;
6725 int32_t joy = joystick_index;
6726 int32_t stick_1 = js_stick_1_x_stick;
6727 int32_t stick_2 = js_stick_2_x_stick;
6728
6729 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6730 if(analog_movement)
6731 gamepad_dlg[56].flags|=D_SELECTED;
6732 else
6733 gamepad_dlg[56].flags&=~D_SELECTED;
6734
6735 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6736 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6737 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6738 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6739 // requires remapping every time.
6740 if (joystick_index >= al_get_num_joysticks())
6741 joystick_index = 0;
6742 gamepad_dlg[61].d2 = joystick_index;
6743
6744 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6745 if (!gamepad_dlg_cur_joystick)
6746 {
6747 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6748 return D_CLOSE;
6749 }
6750
6751 large_dialog(gamepad_dlg);
6752
6753 int32_t ret = do_zqdialog(gamepad_dlg,4);
6754
6755 if(ret == 4) //OK
6756 {
6757 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6758 joystick_index = gamepad_dlg[61].d2;
6759 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6760 if (!gamepad_dlg_cur_joystick)
6761 {
6762 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6763 return D_CLOSE;
6764 }
6765 js_stick_1_y_stick = js_stick_1_x_stick;
6766 js_stick_2_y_stick = js_stick_2_x_stick;
6767 save_control_configs(false);
6768 }
6769 else //Cancel
6770 {
6771 Abtn = a;
6772 Bbtn = b;
6773 Sbtn = s;
6774 Lbtn = l;
6775 Rbtn = r;
6776 Mbtn = m;
6777 Pbtn = p;
6778 Exbtn1 = ex1;
6779 Exbtn2 = ex2;
6780 Exbtn3 = ex3;
6781 Exbtn4 = ex4;
6782 DUbtn = up;
6783 DDbtn = down;
6784 DLbtn = left;
6785 DRbtn = right;
6786 joystick_index = joy;
6787 js_stick_1_x_stick = stick_1;
6788 js_stick_2_x_stick = stick_2;
6789 }
6790
6791 return D_O_K;
6792 }
6793
6794 int32_t onCheatKeys()
6795 {
6796 int32_t oldcheats[Cheat::Last][2];
6797 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6798
6799 bool done=false;
6800
6801 while(!done)
6802 {
6803 bool confirm = false;
6804 CheatKeysDialog(&confirm).show();
6805 if(confirm) // OK
6806 {
6807 std::vector<std::string> uniqueError;
6808 char buf[512];
6809 for(size_t q = 1; q < Cheat::Last; ++q)
6810 {
6811 if(cheatkeys[q][1] && !cheatkeys[q][0])
6812 {
6813 cheatkeys[q][0] = cheatkeys[q][1];
6814 cheatkeys[q][1] = 0;
6815 }
6816 }
6817 for(size_t q = 1; q < Cheat::Last; ++q)
6818 {
6819 if(!bindable_cheat((Cheat)q)) continue;
6820 for(size_t p = q+1; p < Cheat::Last; ++p)
6821 {
6822 if(!bindable_cheat((Cheat)p)) continue;
6823 for(size_t q2 = 0; q2 <= 1; ++q2)
6824 for(size_t p2 = 0; p2 <= 1; ++p2)
6825 {
6826 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6827 {
6828 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6829 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6830 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6831 get_keystr(cheatkeys[q][q2])));
6832 }
6833 }
6834 }
6835 }
6836 if(uniqueError.size() == 0)
6837 {
6838 done = true;
6839 save_cheatkeys();
6840 }
6841 else
6842 {
6843 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6844 box_out("Cannot have duplicate keybinds!"); box_eol();
6845 for(std::vector<std::string>::iterator it = uniqueError.begin();
6846 it != uniqueError.end(); ++it)
6847 {
6848 box_out((*it).c_str()); box_eol();
6849 }
6850 box_end(true);
6851 }
6852 }
6853 else // Cancel
6854 {
6855 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6856 done=true;
6857 }
6858 rest(1);
6859 }
6860
6861 return D_O_K;
6862 }
6863
6864 int32_t onSound()
6865 {
6866 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6867 {
6868 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6869 {
6870 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6871 }
6872 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6873 {
6874 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6875 }
6876 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6877 {
6878 emusic_volume = (int32_t)FFCore.usr_music_volume;
6879 }
6880 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6881 {
6882 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6883 }
6884 }
6885 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6886 {
6887 pan_style = (int32_t)FFCore.usr_panstyle;
6888 }
6889
6890 int32_t m = midi_volume;
6891 int32_t d = digi_volume;
6892 int32_t e = emusic_volume;
6893 int32_t b = zcmusic_bufsz;
6894 int32_t s = sfx_volume;
6895 int32_t p = pan_style;
6896 pan_style = vbound(pan_style,0,3);
6897
6898 sound_dlg[0].dp2=get_zc_font(font_lfont);
6899
6900 large_dialog(sound_dlg);
6901
6902 midi_dp[1] = sound_dlg[6].x;
6903 midi_dp[2] = sound_dlg[6].y;
6904 digi_dp[1] = sound_dlg[7].x;
6905 digi_dp[2] = sound_dlg[7].y;
6906 emus_dp[1] = sound_dlg[8].x;
6907 emus_dp[2] = sound_dlg[8].y;
6908 buf_dp[1] = sound_dlg[9].x;
6909 buf_dp[2] = sound_dlg[9].y;
6910 sfx_dp[1] = sound_dlg[10].x;
6911 sfx_dp[2] = sound_dlg[10].y;
6912 pan_dp[1] = sound_dlg[11].x;
6913 pan_dp[2] = sound_dlg[11].y;
6914 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6915 sound_dlg[16].d2 = (digi_volume==255) ? 32 : digi_volume>>3;
6916 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6917 sound_dlg[18].d2 = zcmusic_bufsz;
6918 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6919 sound_dlg[20].d2 = pan_style;
6920
6921 int32_t ret = do_zqdialog(sound_dlg,1);
6922
6923 if(ret==2)
6924 {
6925 master_volume(digi_volume,midi_volume);
6926 if (zcmusic)
6927 zcmusic_set_volume(zcmusic, emusic_volume);
6928
6929 int32_t temp_volume = sfx_volume;
6930 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6931 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6932 for(int32_t i=0; i<WAV_COUNT; ++i)
6933 {
6934 //allegro assertion fails when passing in -1 as voice -DD
6935 if(sfx_voice[i] > 0)
6936 voice_set_volume(sfx_voice[i], temp_volume);
6937 }
6938 zc_set_config(sfx_sect,"digi",digi_volume);
6939 zc_set_config(sfx_sect,"midi",midi_volume);
6940 zc_set_config(sfx_sect,"sfx",sfx_volume);
6941 zc_set_config(sfx_sect,"emusic",emusic_volume);
6942 zc_set_config(sfx_sect,"pan",pan_style);
6943 zc_set_config(sfx_sect,"zcmusic_bufsz",zcmusic_bufsz);
6944 }
6945 else
6946 {
6947 midi_volume = m;
6948 digi_volume = d;
6949 emusic_volume = e;
6950 zcmusic_bufsz = b;
6951 sfx_volume = s;
6952 pan_style = p;
6953 }
6954
6955 return D_O_K;
6956 }
6957
6958 int32_t queding(char const* s1, char const* s2, char const* s3)
6959 {
6960 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6961 }
6962
6963 int32_t onQuit()
6964 {
6965 if(Playing)
6966 {
6967 int32_t ret=0;
6968
6969 if(get_qr(qr_NOCONTINUE))
6970 {
6971 if(standalone_mode)
6972 {
6973 ret=queding("End current game?",
6974 "The continue screen is disabled; the game",
6975 "will be reloaded from the last save.");
6976 }
6977 else
6978 {
6979 ret=queding("End current game?",
6980 "The continue screen is disabled. You will",
6981 "be returned to the file select screen.");
6982 }
6983 }
6984 else
6985 ret=queding("End current game?",NULL,NULL);
6986
6987 if(ret==1)
6988 {
6989 disableClickToFreeze=false;
6990 Quit=qQUIT;
6991
6992 // Trying to evade a door repair charge?
6993 if(repaircharge)
6994 {
6995 game->change_drupy(-repaircharge);
6996 repaircharge=0;
6997 }
6998
6999 return D_CLOSE;
7000 }
7001 }
7002
7003 return D_O_K;
7004 }
7005
7006 int32_t onTryQuitMenu()
7007 {
7008 return onTryQuit(true);
7009 }
7010
7011 int32_t onTryQuit(bool inMenu)
7012 {
7013 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
7014 {
7015 if(active_cutscene.can_f6())
7016 {
7017 if(get_qr(qr_OLD_F6))
7018 {
7019 if(inMenu) onQuit();
7020 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
7021 }
7022 else
7023 {
7024 disableClickToFreeze=false;
7025 GameFlags |= GAMEFLAG_TRYQUIT;
7026 }
7027 return D_CLOSE;
7028 }
7029 else active_cutscene.error();
7030 }
7031
7032 return D_O_K;
7033 }
7034
7035 int32_t onReset()
7036 {
7037 if(queding(" Reset system? ",NULL,NULL)==1)
7038 {
7039 disableClickToFreeze=false;
7040 Quit=qRESET;
7041 replay_quit();
7042 return D_CLOSE;
7043 }
7044
7045 return D_O_K;
7046 }
7047
7048 int32_t onExit()
7049 {
7050 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
7051 {
7052 Quit=qEXIT;
7053 return D_CLOSE;
7054 }
7055
7056 return D_O_K;
7057 }
7058
7059 int32_t onDebug()
7060 {
7061 if(debug_enabled)
7062 set_debug(!get_debug());
7063 return D_O_K;
7064 }
7065
7066 int32_t onHeartBeep()
7067 {
7068 heart_beep=!heart_beep;
7069 zc_set_config(cfg_sect,"heart_beep",heart_beep);
7070 return D_O_K;
7071 }
7072
7073 int32_t onSaveIndicator()
7074 {
7075 use_save_indicator = use_save_indicator ? 0 : 1;
7076 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
7077 return D_O_K;
7078 }
7079
7080 int32_t onEpilepsy()
7081 {
7082 if(jwin_alert3(
7083 "Epilepsy Flash Reduction",
7084 "Enabling this will reduce the intensity of flashing and screen wave effects.",
7085 "Disabling this will restore standard flash and wavy behaviour.",
7086 "Proceed?",
7087 "&Yes",
7088 "&No",
7089 NULL,
7090 'y',
7091 'n',
7092 0,
7093 get_zc_font(font_lfont)) == 1)
7094 {
7095 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
7096 zc_set_config("zeldadx","checked_epilepsy",1);
7097 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
7098 }
7099 return D_O_K;
7100 }
7101
7102 bool rc = false;
7103
7104 static DIALOG getnum_dlg[] =
7105 {
7106 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
7107 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
7108 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
7109 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
7110 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7111 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7112 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7113 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7114 };
7115
7116 int32_t getnumber(const char *prompt,int32_t initialval)
7117 {
7118 char buf[20];
7119 sprintf(buf,"%d",initialval);
7120 getnum_dlg[0].dp=(void *)prompt;
7121 getnum_dlg[0].dp2=get_zc_font(font_lfont);
7122 getnum_dlg[2].dp=buf;
7123
7124 large_dialog(getnum_dlg);
7125
7126 if(do_zqdialog(getnum_dlg,2)==3)
7127 return atoi(buf);
7128
7129 return initialval;
7130 }
7131
7132 int32_t onLife()
7133 {
7134 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
7135 cheats_enqueue(Cheat::Life, value);
7136 return D_O_K;
7137 }
7138
7139 int32_t onHeartC()
7140 {
7141 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
7142 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
7143 cheats_enqueue(Cheat::MaxLife, max_life);
7144 cheats_enqueue(Cheat::Life, life);
7145 return D_O_K;
7146 }
7147
7148 int32_t onMagicC()
7149 {
7150 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
7151 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
7152 cheats_enqueue(Cheat::MaxMagic, max_magic);
7153 cheats_enqueue(Cheat::Magic, magic);
7154 return D_O_K;
7155 }
7156
7157 int32_t onRupies()
7158 {
7159 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
7160 cheats_enqueue(Cheat::Rupies, value);
7161 return D_O_K;
7162 }
7163
7164 int32_t onMaxBombs()
7165 {
7166 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
7167 cheats_enqueue(Cheat::MaxBombs, value);
7168 cheats_enqueue(Cheat::Bombs, value);
7169 return D_O_K;
7170 }
7171
7172 int32_t onRefillLife()
7173 {
7174 cheats_enqueue(Cheat::Life, game->get_maxlife());
7175 return D_O_K;
7176 }
7177 int32_t onRefillMagic()
7178 {
7179 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
7180 return D_O_K;
7181 }
7182 int32_t onClock()
7183 {
7184 cheats_enqueue(Cheat::Clock);
7185 return D_O_K;
7186 }
7187
7188 int32_t onQstPath()
7189 {
7190 char path[2048];
7191
7192 chop_path(qstdir);
7193 strcpy(path,qstdir);
7194
7195 go();
7196
7197 if(jwin_dfile_select_ex("Quest File Directory", path, "qst", 2048, -1, -1, get_zc_font(font_lfont)))
7198 {
7199 chop_path(path);
7200 fix_filename_case(path);
7201 fix_filename_slashes(path);
7202 strcpy(qstdir,path);
7203 strcpy(qstpath,qstdir);
7204 zc_set_config("zeldadx","quest_dir",qstdir);
7205 flush_config_file();
7206 }
7207
7208 comeback();
7209 return D_O_K;
7210 }
7211
7212 #include "dialog/cheat_dialog.h"
7213 int32_t onCheat()
7214 {
7215 call_setcheat_dialog();
7216 game->set_cheat(maxcheat);
7217 if(cheat) game->did_cheat(true);
7218 return D_O_K;
7219 }
7220
7221 int32_t onCheatRupies()
7222 {
7223 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7224 return D_O_K;
7225 }
7226
7227 int32_t onCheatArrows()
7228 {
7229 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7230 return D_O_K;
7231 }
7232
7233 int32_t onCheatBombs()
7234 {
7235 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7236 return D_O_K;
7237 }
7238
7239 // *** screen saver
7240
7241 9286170 int32_t after_time()
7242 {
7243
1/2
✓ Branch 0 taken 9286170 times.
✗ Branch 1 not taken.
9286170 if(ss_enable == 0)
7244 return INT_MAX;
7245
7246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
9286170 if(ss_after <= 0)
7247 return 5 * 60;
7248
7249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
9286170 if(ss_after <= 3)
7250 return ss_after * 15 * 60;
7251
7252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286170 times.
9286170 if(ss_after <= 13)
7253 return (ss_after - 3) * 60 * 60;
7254
7255 9286170 return MAX_IDLE + 1;
7256 9286170 }
7257
7258 static const char *after_str[15] =
7259 {
7260 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7261 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7262 "Never"
7263 };
7264
7265 const char *after_list(int32_t index, int32_t *list_size)
7266 {
7267 if(index < 0)
7268 {
7269 *list_size = 15;
7270 return NULL;
7271 }
7272
7273 return after_str[index];
7274 }
7275
7276 116 static ListData after__list(after_list, &font);
7277
7278 static DIALOG scrsaver_dlg[] =
7279 {
7280 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7281 116 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7282 116 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7283 116 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7284 116 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7285 116 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7286 116 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7287 116 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7288 116 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7289 116 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7290 116 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7291 116 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7292 116 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7293 116 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7294 };
7295
7296 int32_t onScreenSaver()
7297 {
7298 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7299 int32_t oldcfgs[3];
7300 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7301 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7302 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7303
7304 large_dialog(scrsaver_dlg);
7305
7306 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7307
7308 if(ret == 8 || ret == 9)
7309 {
7310 ss_after = scrsaver_dlg[5].d1;
7311 ss_speed = scrsaver_dlg[6].d2;
7312 ss_density = scrsaver_dlg[7].d2;
7313 if(oldcfgs[0] != ss_after)
7314 zc_set_config(cfg_sect,"ss_after",ss_after);
7315 if(oldcfgs[1] != ss_speed)
7316 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7317 if(oldcfgs[2] != ss_density)
7318 zc_set_config(cfg_sect,"ss_density",ss_density);
7319 }
7320
7321 if(ret == 9)
7322 // preview Screen Saver
7323 {
7324 clear_keybuf();
7325 Matrix(ss_speed, ss_density, 30);
7326 system_pal(true);
7327 sys_mouse();
7328 }
7329
7330 return D_O_K;
7331 }
7332
7333 /***** Menus *****/
7334
7335 static MENU game_menu[] =
7336 {
7337 { (char *)"&Continue\tESC", onContinue, NULL, 0, NULL },
7338 { (char *)"", NULL, NULL, 0, NULL },
7339 { (char *)"L&oad Quest...", onCustomGame, NULL, 0, NULL },
7340 { (char *)"&End Game\tF6", onTryQuitMenu, NULL, 0, NULL },
7341 { (char *)"", NULL, NULL, 0, NULL },
7342 #ifdef __EMSCRIPTEN__
7343 { (char *)"&Reset\tF7", onReset, NULL, 0, NULL },
7344 #elif defined(ALLEGRO_MACOSX)
7345 { (char *)"&Reset\tF7", onReset, NULL, 0, NULL },
7346 { (char *)"&Quit\tF8", onExit, NULL, 0, NULL },
7347 #else
7348 { (char *)"&Reset\tF9", onReset, NULL, 0, NULL },
7349 { (char *)"&Quit\tF10", onExit, NULL, 0, NULL },
7350 #endif
7351 { NULL, NULL, NULL, 0, NULL }
7352 };
7353
7354 static MENU snapshot_format_menu[] =
7355 {
7356 { (char *)"&BMP", onSetSnapshotFormat, NULL, 0, NULL },
7357 { (char *)"&GIF", onSetSnapshotFormat, NULL, 0, NULL },
7358 { (char *)"&JPG", onSetSnapshotFormat, NULL, 0, NULL },
7359 { (char *)"&PNG", onSetSnapshotFormat, NULL, 0, NULL },
7360 { (char *)"PC&X", onSetSnapshotFormat, NULL, 0, NULL },
7361 { (char *)"&TGA", onSetSnapshotFormat, NULL, 0, NULL },
7362 { NULL, NULL, NULL, 0, NULL }
7363 };
7364
7365 static MENU controls_menu[] =
7366 {
7367 { (char *)"Key&board...", onKeyboard, NULL, 0, NULL },
7368 { (char *)"&Gamepad...", onGamepad, NULL, 0, NULL },
7369 { (char *)"&Cheat Keys...", onCheatKeys, NULL, 0, NULL },
7370 { NULL, NULL, NULL, 0, NULL }
7371 };
7372
7373 static MENU name_entry_mode_menu[] =
7374 {
7375 { (char *)"&Keyboard", onKeyboardEntry, NULL, 0, NULL },
7376 { (char *)"&Letter Grid", onLetterGridEntry, NULL, 0, NULL },
7377 { (char *)"&Extended Letter Grid", onExtLetterGridEntry, NULL, 0, NULL },
7378 { NULL, NULL, NULL, 0, NULL }
7379 };
7380
7381 static void set_controls_menu_active()
7382 {
7383
7384 }
7385
7386 static MENU window_menu[] =
7387 {
7388 { "Lock Aspect Ratio", onDragAspect, NULL, 0, NULL },
7389 { "Lock Integer Scale", onIntegerScaling, NULL, 0, NULL },
7390 { "Save Size Changes", onSaveDragResize, NULL, 0, NULL },
7391 { "Save Position Changes", onWinPosSave, NULL, 0, NULL },
7392 { "Stretch Game Area", onStretchGame, NULL, 0, NULL },
7393 { NULL, NULL, NULL, 0, NULL }
7394 };
7395 static MENU options_menu[] =
7396 {
7397 { "Name &Entry Mode", NULL, name_entry_mode_menu, 0, NULL },
7398 { "S&napshot Format", NULL, snapshot_format_menu, 0, NULL },
7399 { "&Window Settings", NULL, window_menu, 0, NULL },
7400 { "Epilepsy Flash Reduction", onEpilepsy, NULL, 0, NULL },
7401 { "Pause In Background", onPauseInBackground, NULL, 0, NULL },
7402 { NULL, NULL, NULL, 0, NULL }
7403 };
7404 static MENU settings_menu[] =
7405 {
7406 { "&Sound...", onSound, NULL, 0, NULL },
7407 { "C&ontrols", NULL, controls_menu, 0, NULL },
7408 { "", NULL, NULL, 0, NULL },
7409 { "Options", NULL, options_menu, 0, NULL },
7410 { "", NULL, NULL, 0, NULL },
7411 //
7412 { "&Cap FPS\tF1", onVsync, NULL, 0, NULL },
7413 { "Show &FPS\tF2", onShowFPS, NULL, 0, NULL },
7414 { "Click to Freeze", onClickToFreeze, NULL, 0, NULL },
7415 { "Cont. &Heart Beep", onHeartBeep, NULL, 0, NULL },
7416 { "Show Trans. &Layers", onTransLayers, NULL, 0, NULL },
7417 //
7418 { "Up+A+B To &Quit", onNESquit, NULL, 0, NULL },
7419 { "Volume &Keys", onVolKeys, NULL, 0, NULL },
7420 { "Sa&ve Indicator", onSaveIndicator, NULL, 0, NULL },
7421 { "", NULL, NULL, 0, NULL },
7422 { "Debu&g", onDebug, NULL, 0, NULL },
7423 //
7424 { NULL, NULL, NULL, 0, NULL }
7425 };
7426
7427
7428 static MENU misc_menu[] =
7429 {
7430 { (char *)"&About...", onAbout, NULL, 0, NULL },
7431 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7432 { (char *)"&Credits...", onCredits, NULL, D_DISABLED, NULL },
7433 { (char *)"&Fullscreen", onFullscreenMenu, NULL, 0, NULL },
7434 { (char *)"&Video Mode...", onVidMode, NULL, 0, NULL },
7435 { (char *)"", NULL, NULL, 0, NULL },
7436 //5
7437 { (char *)"&Quest Info...", onQuest, NULL, 0, NULL },
7438 { (char *)"Quest &MIDI Info...", onMIDICredits, NULL, 0, NULL },
7439 { (char *)"Quest &Directory...", onQstPath, NULL, 0, NULL },
7440 { (char *)"", NULL, NULL, 0, NULL },
7441 { (char *)"Take &Snapshot\tF12", onSnapshot, NULL, 0, NULL },
7442 //10
7443 { (char *)"Sc&reen Saver...", onScreenSaver, NULL, 0, NULL },
7444 { (char *)"Save ZC Configuration", OnSaveZCConfig, NULL, 0, NULL },
7445 { (char *)"Show ZASM Debugger", onConsoleZASM, NULL, 0, NULL },
7446 { (char *)"Show ZScript Debugger", onConsoleZScript, NULL, 0, NULL },
7447 { (char *)"Clear Console on Qst Load", onClrConsoleOnLoad, NULL, 0, NULL },
7448 //15
7449 { (char *)"Clear Directory Cache", OnnClearQuestDir, NULL, 0, NULL },
7450 { NULL, NULL, NULL, 0, NULL }
7451 };
7452
7453 static MENU refill_menu[] =
7454 {
7455 { (char *)"&Life", onRefillLife, NULL, 0, NULL },
7456 { (char *)"&Magic", onRefillMagic, NULL, 0, NULL },
7457 { (char *)"&Bombs", onCheatBombs, NULL, 0, NULL },
7458 { (char *)"&Rupees", onCheatRupies, NULL, 0, NULL },
7459 { (char *)"&Arrows", onCheatArrows, NULL, 0, NULL },
7460 { NULL, NULL, NULL, 0, NULL }
7461 };
7462
7463 static MENU show_menu[] =
7464 {
7465 { (char *)"Combos", onShowLayer0, NULL, 0, NULL },
7466 { (char *)"Layer 1", onShowLayer1, NULL, 0, NULL },
7467 { (char *)"Layer 2", onShowLayer2, NULL, 0, NULL },
7468 { (char *)"Layer 3", onShowLayer3, NULL, 0, NULL },
7469 { (char *)"Layer 4", onShowLayer4, NULL, 0, NULL },
7470 { (char *)"Layer 5", onShowLayer5, NULL, 0, NULL },
7471 { (char *)"Layer 6", onShowLayer6, NULL, 0, NULL },
7472 { (char *)"Overhead Combos", onShowLayerO, NULL, 0, NULL },
7473 { (char *)"Push Blocks", onShowLayerP, NULL, 0, NULL },
7474 { (char *)"Freeform Combos", onShowLayerF, NULL, 0, NULL },
7475 { (char *)"Sprites", onShowLayerS, NULL, 0, NULL },
7476 { (char *)"", NULL, NULL, 0, NULL },
7477 { (char *)"Current FFC Scripts", onShowFFScripts, NULL, 0, NULL },
7478 { (char *)"", NULL, NULL, 0, NULL },
7479 { (char *)"Walkability", onShowLayerW, NULL, 0, NULL },
7480 { (char *)"Hitboxes", onShowHitboxes, NULL, 0, NULL },
7481 { (char *)"Effects", onShowLayerE, NULL, 0, NULL },
7482 { (char *)"Info Opacity", onShowInfoOpacity, NULL, 0, NULL },
7483 { NULL, NULL, NULL, 0, NULL }
7484 };
7485
7486 static MENU cheat_menu[] =
7487 {
7488 { (char *)"Set &Cheat", onCheat, NULL, 0, NULL },
7489 { (char *)"", NULL, NULL, 0, NULL },
7490 { (char *)"Re&fill", NULL, refill_menu, 0, NULL },
7491 { (char *)"", NULL, NULL, 0, NULL },
7492 { (char *)"&Invincible", onClock, NULL, 0, NULL },
7493 { (char *)"Ma&x Bombs...", onMaxBombs, NULL, 0, NULL },
7494 { (char *)"&Heart Containers...", onHeartC, NULL, 0, NULL },
7495 { (char *)"&Magic Containers...", onMagicC, NULL, 0, NULL },
7496 { (char *)"", NULL, NULL, 0, NULL },
7497 { (char *)"&Player Data...", onCheatConsole, NULL, 0, NULL },
7498 { (char *)"", NULL, NULL, 0, NULL },
7499 { (char *)"Walk Through &Walls", onNoWalls, NULL, 0, NULL },
7500 { (char *)"Player Ignores Side&view", onIgnoreSideview, NULL, 0, NULL },
7501 { (char *)"&Quick Movement", onGoFast, NULL, 0, NULL },
7502 { (char *)"&Kill All Enemies", onKillCheat, NULL, 0, NULL },
7503 { (char *)"Trigger &Secrets", onSecretsCheat, NULL, 0, NULL },
7504 { (char *)"Trigger Secrets Perm", onSecretsCheatPerm, NULL, 0, NULL },
7505 { (char *)"Show/Hide Layer", NULL, show_menu, 0, NULL },
7506 { (char *)"Toggle &Light", onLightSwitch, NULL, 0, NULL },
7507 { (char *)"&Goto Location...", onGoTo, NULL, 0, NULL },
7508 { NULL, NULL, NULL, 0, NULL }
7509 };
7510
7511 #if DEVLEVEL > 0
7512 int32_t devLogging();
7513 int32_t devDebug();
7514 int32_t devTimestmp();
7515 #if DEVLEVEL > 1
7516 int32_t setCheat();
7517 #endif //DEVLEVEL > 1
7518 enum
7519 {
7520 dv_log,
7521 // dv_dbg,
7522 dv_tmpstmp,
7523 #if DEVLEVEL > 1
7524 dv_nil,
7525 dv_setcheat,
7526 #endif //DEVLEVEL > 1
7527 dv_max
7528 };
7529 static MENU dev_menu[] =
7530 {
7531 { (char *)"&Force Error Log", devLogging, NULL, 0, NULL },
7532 // { (char *)"&Extra Debug Log", devDebug, NULL, 0, NULL },
7533 { (char *)"&Timestamp Log", devTimestmp, NULL, 0, NULL },
7534 #if DEVLEVEL > 1
7535 { (char *)"", NULL, NULL, 0, NULL },
7536 { (char *)"Set &Cheat", setCheat, NULL, 0, NULL },
7537 #endif //DEVLEVEL > 1
7538 { NULL, NULL, NULL, 0, NULL }
7539 };
7540 int32_t devLogging()
7541 {
7542 dev_logging = !dev_logging;
7543 dev_menu[dv_log].flags = dev_logging ? D_SELECTED : 0;
7544 return D_O_K;
7545 }
7546 // int32_t devDebug()
7547 // {
7548 // dev_debug = !dev_debug;
7549 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7550 // return D_O_K;
7551 // }
7552 int32_t devTimestmp()
7553 {
7554 dev_timestmp = !dev_timestmp;
7555 dev_menu[dv_tmpstmp].flags = dev_timestmp ? D_SELECTED : 0;
7556 return D_O_K;
7557 }
7558 #if DEVLEVEL > 1
7559 int32_t setCheat()
7560 {
7561 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7562 return D_O_K;
7563 }
7564 #endif //DEVLEVEL > 1
7565 #endif //DEVLEVEL > 0
7566
7567 MENU the_player_menu[] =
7568 {
7569 { (char *)"&Game", NULL, game_menu, 0, NULL },
7570 { (char *)"&Settings", NULL, settings_menu, 0, NULL },
7571 { (char *)"&Cheat", NULL, cheat_menu, 0, NULL },
7572 { (char *)"Replay", NULL, replay_menu, 0, NULL },
7573 { (char *)"&ZC", NULL, misc_menu, 0, NULL },
7574 #if DEVLEVEL > 0
7575 { (char *)"&Dev", NULL, dev_menu, 0, NULL },
7576 #endif
7577 { NULL, NULL, NULL, 0, NULL }
7578 };
7579 int32_t onPauseInBackground()
7580 {
7581 if(jwin_alert3(
7582 "Toggle Pause In Background",
7583 "This action will change whether ZC Player pauses when the window loses focus.",
7584 "",
7585 "Proceed?",
7586 "&Yes",
7587 "&No",
7588 NULL,
7589 'y',
7590 'n',
7591 0,
7592 get_zc_font(font_lfont)) == 1)
7593 {
7594 pause_in_background = pause_in_background ? 0 : 1;
7595 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7596 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7597 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7598 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7599 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7600 }
7601 options_menu[4].flags =(pause_in_background)?D_SELECTED:0;
7602 return D_O_K;
7603 }
7604
7605 int32_t onKeyboardEntry()
7606 {
7607 NameEntryMode=0;
7608 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7609 return D_O_K;
7610 }
7611
7612 int32_t onLetterGridEntry()
7613 {
7614 NameEntryMode=1;
7615 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7616 return D_O_K;
7617 }
7618
7619 int32_t onExtLetterGridEntry()
7620 {
7621 NameEntryMode=2;
7622 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7623 return D_O_K;
7624 }
7625
7626 static BITMAP* oldscreen;
7627 int32_t onFullscreenMenu()
7628 {
7629 // super hacks
7630 screen = oldscreen;
7631 if (onFullscreen() == D_REDRAW)
7632 {
7633 oldscreen = screen;
7634 }
7635 screen = menu_bmp;
7636 misc_menu[2].flags =(isFullScreen()==1)?D_SELECTED:0;
7637 return D_O_K;
7638 }
7639
7640 116 void fix_menu()
7641 {
7642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
116 if(!debug_enabled)
7643 116 settings_menu[13].text = NULL;
7644 116 }
7645
7646 static DIALOG system_dlg[] =
7647 {
7648 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
7649 { jwin_menu_proc, 0, 0, 0, 0, 0, 0, 0, D_USER, 0, 0, (void *) the_player_menu, NULL, NULL },
7650 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onVsync, NULL, NULL },
7651 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F2, 0, (void *) onShowFPS, NULL, NULL },
7652 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F6, 0, (void *) onTryQuitMenu, NULL, NULL },
7653 #ifndef ALLEGRO_MACOSX
7654 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F9, 0, (void *) onReset, NULL, NULL },
7655 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F10, 0, (void *) onExit, NULL, NULL },
7656 #else
7657 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F7, 0, (void *) onReset, NULL, NULL },
7658 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F8, 0, (void *) onExit, NULL, NULL },
7659 #endif
7660 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F12, 0, (void *) onSnapshot, NULL, NULL },
7661 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_TAB, 0, (void *) onDebug, NULL, NULL },
7662 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7663 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7664 };
7665
7666 void reset_snapshot_format_menu()
7667 {
7668 for(int32_t i=0; i<ssfmtMAX; ++i)
7669 {
7670 snapshot_format_menu[i].flags=0;
7671 }
7672 }
7673
7674 int32_t onSetSnapshotFormat()
7675 {
7676 switch(active_menu->text[1])
7677 {
7678 case 'B': //"&BMP"
7679 SnapshotFormat=0;
7680 break;
7681
7682 case 'G': //"&GIF"
7683 SnapshotFormat=1;
7684 break;
7685
7686 case 'J': //"&JPG"
7687 SnapshotFormat=2;
7688 break;
7689
7690 case 'P': //"&PNG"
7691 SnapshotFormat=3;
7692 break;
7693
7694 case 'C': //"PC&X"
7695 SnapshotFormat=4;
7696 break;
7697
7698 case 'T': //"&TGA"
7699 SnapshotFormat=5;
7700 break;
7701
7702 case 'L': //"&LBM"
7703 SnapshotFormat=6;
7704 break;
7705 }
7706 zc_set_config("zeldadx", "snapshot_format", SnapshotFormat);
7707
7708 snapshot_format_menu[SnapshotFormat].flags=D_SELECTED;
7709 return D_O_K;
7710 }
7711
7712
7713 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7714 {
7715 PALETTE tmp;
7716
7717 for(int32_t i=0; i<256; i++)
7718 {
7719 tmp[i].r=r;
7720 tmp[i].g=g;
7721 tmp[i].b=b;
7722 }
7723
7724 fade_interpolate(src,tmp,dest,pos,from,to);
7725 }
7726
7727 14 void system_pal(bool force)
7728 {
7729
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(is_sys_pal && !force) return;
7730 14 is_sys_pal = true;
7731 14 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7732 14 hw_palette = &syspal;
7733 14 update_hw_pal = true;
7734 14 }
7735
7736 static uint32_t entered_sys_pal = 0;
7737 14 void enter_sys_pal()
7738 {
7739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(is_sys_pal)
7740 {
7741 if(entered_sys_pal)
7742 ++entered_sys_pal;
7743 return;
7744 }
7745 14 sys_mouse();
7746 14 system_pal(true);
7747 14 ++entered_sys_pal;
7748 14 }
7749 14 void exit_sys_pal()
7750 {
7751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(entered_sys_pal)
7752 {
7753
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!--entered_sys_pal)
7754 {
7755 14 game_pal();
7756 14 game_mouse();
7757 14 }
7758 14 }
7759 14 }
7760
7761 void switch_out_callback()
7762 {
7763 if (pause_in_background && !MenuOpen)
7764 {
7765 System();
7766 }
7767 }
7768
7769 void switch_in_callback()
7770 {
7771 }
7772
7773 423 void game_pal()
7774 {
7775 423 is_sys_pal = false;
7776 423 entered_sys_pal = 0;
7777 423 hw_palette = &RAMpal;
7778 423 update_hw_pal = true;
7779 423 }
7780
7781 static char bar_str[] = "";
7782
7783 14 void music_pause()
7784 {
7785 //al_pause_duh(tmplayer);
7786 14 zcmusic_pause(zcmusic, ZCM_PAUSE);
7787
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(zcmixer->oldtrack)
7788 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7789 14 zc_midi_pause();
7790 14 }
7791
7792 void music_resume()
7793 {
7794 //al_resume_duh(tmplayer);
7795 zcmusic_pause(zcmusic, ZCM_RESUME);
7796 if (zcmixer->oldtrack)
7797 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7798 zc_midi_resume();
7799 }
7800
7801 3360 void music_stop()
7802 {
7803 //al_stop_duh(tmplayer);
7804 //unload_duh(tmusic);
7805 //tmusic=NULL;
7806 //tmplayer=NULL;
7807 3360 zcmusic_stop(zcmusic);
7808 3360 zcmusic_unload_file(zcmusic);
7809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3360 times.
3360 if (zcmixer->oldtrack)
7810 {
7811 zcmusic_stop(zcmixer->oldtrack);
7812 zcmusic_unload_file(zcmixer->oldtrack);
7813 }
7814 3360 zcmixer->newtrack = NULL;
7815 3360 zc_stop_midi();
7816 3360 currmidi=-1;
7817 3360 }
7818
7819 void System()
7820 {
7821 mouse_down=gui_mouse_b();
7822 music_pause();
7823 pause_all_sfx();
7824 MenuOpen = true;
7825 enter_sys_pal();
7826 // FONT *oldfont=font;
7827 // font=tfont;
7828
7829 misc_menu[2].flags =(isFullScreen()==1)?D_SELECTED:0;
7830 misc_menu[3].flags =(isFullScreen()==1)?D_DISABLED:0;
7831
7832 game_menu[2].flags = getsaveslot() > -1 ? 0 : D_DISABLED;
7833 #if DEVLEVEL > 1
7834 dev_menu[dv_setcheat].flags = Playing ? 0 : D_DISABLED;
7835 #endif
7836 game_menu[3].flags =
7837 misc_menu[5].flags = Playing ? 0 : D_DISABLED;
7838 misc_menu[7].flags = !Playing ? 0 : D_DISABLED;
7839 clear_keybuf();
7840
7841 DIALOG_PLAYER *p;
7842
7843 clear_bitmap(menu_bmp);
7844 oldscreen = screen;
7845 screen = menu_bmp;
7846
7847 p = init_dialog(system_dlg,-1);
7848
7849 // drop the menu on startup if menu button pressed
7850 if(joybtn(Mbtn)||zc_getrawkey(KEY_ESC))
7851 simulate_keypress(KEY_G << 8);
7852
7853 do
7854 {
7855 if(handle_close_btn_quit())
7856 break;
7857
7858 rest(17);
7859
7860 if(mouse_down && !gui_mouse_b())
7861 mouse_down=0;
7862
7863 settings_menu[1].flags = replay_is_replaying() ? D_DISABLED : 0;
7864 settings_menu[5].flags = Throttlefps?D_SELECTED:0;
7865 settings_menu[6].flags = ShowFPS?D_SELECTED:0;
7866 settings_menu[7].flags = ClickToFreeze?D_SELECTED:0;
7867 settings_menu[9].flags = TransLayers?D_SELECTED:0;
7868 settings_menu[10].flags = NESquit?D_SELECTED:0;
7869 settings_menu[11].flags = volkeys?D_SELECTED:0;
7870
7871 window_menu[0].flags = DragAspect?D_SELECTED:0;
7872 window_menu[1].flags = scaleForceInteger?D_SELECTED:0;
7873 window_menu[2].flags = SaveDragResize?D_SELECTED:0;
7874 window_menu[3].flags = SaveWinPos?D_SELECTED:0;
7875 window_menu[4].flags = stretchGame?D_SELECTED:0;
7876
7877 options_menu[3].flags = (epilepsyFlashReduction) ? D_SELECTED : 0;
7878 options_menu[4].flags = (pause_in_background)?D_SELECTED:0;
7879
7880 name_entry_mode_menu[0].flags = (NameEntryMode==0)?D_SELECTED:0;
7881 name_entry_mode_menu[1].flags = (NameEntryMode==1)?D_SELECTED:0;
7882 name_entry_mode_menu[2].flags = (NameEntryMode==2)?D_SELECTED:0;
7883
7884 misc_menu[12].flags =(zasm_debugger)?D_SELECTED:0;
7885 misc_menu[13].flags =(zscript_debugger)?D_SELECTED:0;
7886 misc_menu[14].flags =(clearConsoleOnLoad)?D_SELECTED:0;
7887
7888 bool nocheat = (replay_is_replaying() || !Playing
7889 || (!zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7890 the_player_menu[2].flags = nocheat ? D_DISABLED : 0;
7891 cheat_menu[0].flags = 0;
7892 refill_menu[4].flags = get_qr(qr_TRUEARROWS) ? 0 : D_DISABLED;
7893 cheat_menu[1].text = (cheat >= 1) || get_debug() ? bar_str : NULL;
7894 cheat_menu[3].text = (cheat >= 2) || get_debug() ? bar_str : NULL;
7895 cheat_menu[8].text = (cheat >= 3) || get_debug() ? bar_str : NULL;
7896 cheat_menu[10].text = (cheat >= 4) || get_debug() ? bar_str : NULL;
7897 cheat_menu[4].flags = getClock() ? D_SELECTED : 0;
7898 cheat_menu[11].flags = toogam ? D_SELECTED : 0;
7899 cheat_menu[12].flags = ignoreSideview ? D_SELECTED : 0;
7900 cheat_menu[13].flags = gofast ? D_SELECTED : 0;
7901
7902 show_menu[0].flags = show_layer_0 ? D_SELECTED : 0;
7903 show_menu[1].flags = show_layer_1 ? D_SELECTED : 0;
7904 show_menu[2].flags = show_layer_2 ? D_SELECTED : 0;
7905 show_menu[3].flags = show_layer_3 ? D_SELECTED : 0;
7906 show_menu[4].flags = show_layer_4 ? D_SELECTED : 0;
7907 show_menu[5].flags = show_layer_5 ? D_SELECTED : 0;
7908 show_menu[6].flags = show_layer_6 ? D_SELECTED : 0;
7909 show_menu[7].flags = show_layer_over ? D_SELECTED : 0;
7910 show_menu[8].flags = show_layer_push ? D_SELECTED : 0;
7911 show_menu[9].flags = show_sprites ? D_SELECTED : 0;
7912 show_menu[10].flags = show_ffcs ? D_SELECTED : 0;
7913 show_menu[12].flags = show_walkflags ? D_SELECTED : 0;
7914 show_menu[13].flags = show_ff_scripts ? D_SELECTED : 0;
7915 show_menu[14].flags = show_hitboxes ? D_SELECTED : 0;
7916 show_menu[15].flags = show_effectflags ? D_SELECTED : 0;
7917
7918 settings_menu[8].flags = heart_beep ? D_SELECTED : 0;
7919 settings_menu[12].flags = use_save_indicator ? D_SELECTED : 0;
7920
7921 replay_menu[0].text = zc_get_config("zeldadx", "replay_new_saves", false) ?
7922 (char *)"Disable recording new saves" :
7923 (char *)"Enable recording new saves";
7924 replay_menu[1].flags = replay_is_active() ? 0 : D_DISABLED;
7925 replay_menu[1].text = replay_get_mode() == ReplayMode::Record ?
7926 (char *)"Stop recording" :
7927 (char *)"Stop replaying";
7928 replay_menu[5].flags = replay_get_mode() == ReplayMode::Record ? 0 : D_DISABLED;
7929 replay_menu[6].text = replay_is_snapshot_all_frames() ?
7930 (char *)"Disable snapshot all frames" :
7931 (char *)"Enable snapshot all frames";
7932
7933 reset_snapshot_format_menu();
7934 snapshot_format_menu[SnapshotFormat].flags = D_SELECTED;
7935
7936 if(debug_enabled)
7937 {
7938 settings_menu[14].flags = get_debug() ? D_SELECTED : 0;
7939 }
7940
7941 if(gui_mouse_b() && !mouse_down)
7942 break;
7943
7944 // press menu to drop the menu
7945 if(rMbtn())
7946 simulate_keypress(KEY_G << 8);
7947
7948 if(input_idle(true) > after_time())
7949 // run Screeen Saver
7950 {
7951 // Screen saver enabled for now.
7952 clear_keybuf();
7953 Matrix(ss_speed, ss_density, 0);
7954 system_pal(true);
7955 sys_mouse();
7956 broadcast_dialog_message(MSG_DRAW, 0);
7957 }
7958
7959 update_hw_screen();
7960 }
7961 while(update_dialog(p));
7962
7963 screen = oldscreen;
7964
7965 // font=oldfont;
7966 mouse_down=gui_mouse_b();
7967 shutdown_dialog(p);
7968 MenuOpen = false;
7969 if(Quit)
7970 {
7971 kill_sfx();
7972 music_stop();
7973 update_hw_screen();
7974 }
7975 else
7976 {
7977 music_resume();
7978 resume_all_sfx();
7979
7980 if(rc)
7981 ringcolor(false);
7982 }
7983 exit_sys_pal();
7984
7985 eat_buttons();
7986
7987 rc=false;
7988 clear_keybuf();
7989
7990 zc_init_apply_cheat_delta();
7991 }
7992
7993 116 void fix_dialogs()
7994 {
7995 116 jwin_center_dialog(about_dlg);
7996 116 jwin_center_dialog(gamepad_dlg);
7997 116 jwin_center_dialog(credits_dlg);
7998 116 jwin_center_dialog(gamemode_dlg);
7999 116 jwin_center_dialog(getnum_dlg);
8000 116 jwin_center_dialog(goto_dlg);
8001 116 jwin_center_dialog(keyboard_control_dlg);
8002 116 jwin_center_dialog(midi_dlg);
8003 116 jwin_center_dialog(quest_dlg);
8004 116 jwin_center_dialog(scrsaver_dlg);
8005 116 jwin_center_dialog(sound_dlg);
8006 116 jwin_center_dialog(triforce_dlg);
8007
8008 // digi_dp[1] += scrx;
8009 // digi_dp[2] += scry;
8010 // midi_dp[1] += scrx;
8011 // midi_dp[2] += scry;
8012 // pan_dp[1] += scrx;
8013 // pan_dp[2] += scry;
8014 // emus_dp[1] += scrx;
8015 // emus_dp[2] += scry;
8016 // buf_dp[1] += scrx;
8017 // buf_dp[2] += scry;
8018 // sfx_dp[1] += scrx;
8019 // sfx_dp[2] += scry;
8020 116 }
8021
8022 /*****************************/
8023 /**** Custom Sound System ****/
8024 /*****************************/
8025
8026 116 INLINE int32_t mixvol(int32_t v1,int32_t v2)
8027 {
8028
2/4
✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
116 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
8029 }
8030
8031 // Run an NSF, or a MIDI if the NSF is missing somehow.
8032 149 bool try_zcmusic(const char *filename, int32_t track, int32_t midi, int32_t fadeoutframes)
8033 {
8034 149 ZCMUSIC *newzcmusic = zcmusic_load_for_quest(filename, qstpath);
8035
8036 // Found it
8037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if(newzcmusic!=NULL)
8038 {
8039 newzcmusic->fadevolume = 10000;
8040 newzcmusic->fadeoutframes = fadeoutframes;
8041
8042 zcmixer->newtrack = newzcmusic;
8043
8044 zcmusic_stop(zcmusic);
8045 zcmusic_unload_file(zcmusic);
8046 zc_stop_midi();
8047
8048 zcmusic=newzcmusic;
8049 int32_t temp_volume = emusic_volume;
8050 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8051 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
8052 temp_volume = (temp_volume * zcmusic->fadevolume) / 10000;
8053 zcmusic_play(zcmusic, temp_volume);
8054
8055 if(track>0)
8056 zcmusic_change_track(zcmusic,track);
8057
8058 return true;
8059 }
8060
8061 // Not found, play MIDI - unless this was called by a script (yay, magic numbers)
8062
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 70 times.
149 else if(midi>-1000)
8063 70 jukebox(midi);
8064
8065 149 return false;
8066 149 }
8067
8068 bool try_zcmusic_ex(char *filename, int32_t track, int32_t midi)
8069 {
8070 ZCMUSIC *newzcmusic = zcmusic_load_for_quest(filename, qstpath);
8071 // Found it
8072 if(newzcmusic!=NULL)
8073 {
8074 zcmusic_stop(zcmusic);
8075 zcmusic_unload_file(zcmusic);
8076 zc_stop_midi();
8077
8078 zcmusic=newzcmusic;
8079 zcmusic_play(zcmusic, emusic_volume);
8080
8081 if(track>0)
8082 zcmusic_change_track(zcmusic,track);
8083
8084 return true;
8085 }
8086
8087 // Not found, play MIDI - unless this was called by a script (yay, magic numbers)
8088 else if(midi>-1000)
8089 jukebox(midi);
8090
8091 return false;
8092 }
8093
8094 int32_t get_zcmusicpos()
8095 {
8096 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
8097 return debugtracething;
8098 return 0;
8099 }
8100
8101 void set_zcmusicpos(int32_t position)
8102 {
8103 zcmusic_set_curpos(zcmusic, position);
8104 }
8105
8106 void set_zcmusicspeed(int32_t speed)
8107 {
8108 zcmusic_set_speed(zcmusic, speed);
8109 }
8110
8111 int32_t get_zcmusiclen()
8112 {
8113 return zcmusic_get_length(zcmusic);
8114 }
8115
8116 void set_zcmusicloop(double start, double end)
8117 {
8118 zcmusic_set_loop(zcmusic, start, end);
8119 }
8120
8121 63941 void jukebox(int32_t index,int32_t loop)
8122 {
8123
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if (is_headless())
8124 63941 return;
8125
8126 music_stop();
8127
8128 if(index<0) index=MAXMIDIS-1;
8129
8130 if(index>=MAXMIDIS) index=0;
8131
8132 music_stop();
8133
8134 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8135 // stuck notes when a song stops. This fixes it.
8136 if(strcmp(midi_driver->name, "DIGMID")==0)
8137 zc_set_volume(0, 0);
8138
8139 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8140 zc_play_midi((MIDI*)tunes[index].data,loop);
8141
8142 if(tunes[index].start>0)
8143 zc_midi_seek(tunes[index].start);
8144
8145 midi_loop_start = tunes[index].loop_start;
8146 midi_loop_end = tunes[index].loop_end;
8147
8148 currmidi=index;
8149 master_volume(digi_volume, midi_volume);
8150 //midi_paused=false;
8151 63941 }
8152
8153 63941 void jukebox(int32_t index)
8154 {
8155
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if(index<0) index=MAXMIDIS-1;
8156
8157
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if(index>=MAXMIDIS) index=0;
8158
8159 // do nothing if it's already playing
8160
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 63941 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
63941 if(index==currmidi && midi_pos>=0)
8161 {
8162 return;
8163 }
8164
8165 63941 jukebox(index,tunes[index].loop);
8166 63941 }
8167
8168 16 void play_DmapMusic()
8169 {
8170
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (is_headless())
8171 16 return;
8172
8173 static char tfile[2048];
8174 static int32_t ttrack=0;
8175 bool domidi=false;
8176
8177 int32_t fadeoutframes = 0;
8178 if (zcmusic != NULL)
8179 fadeoutframes = zcmusic->fadeoutframes;
8180
8181 if(DMaps[currdmap].tmusic[0]!=0)
8182 {
8183 if(zcmusic==NULL ||
8184 strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 ||
8185 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack))
8186 {
8187 if (DMaps[currdmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8188 {
8189 if (FFCore.play_enh_music_crossfade(DMaps[currdmap].tmusic, DMaps[currdmap].tmusictrack, DMaps[currdmap].tmusic_xfade_in, fadeoutframes))
8190 {
8191 if (zcmusic != NULL)
8192 {
8193 zcmusic->fadeoutframes = DMaps[currdmap].tmusic_xfade_out;
8194 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8195 }
8196 }
8197 }
8198 else
8199 {
8200 if (zcmusic != NULL)
8201 {
8202 zcmusic_stop(zcmusic);
8203 zcmusic_unload_file(zcmusic);
8204 zcmusic = NULL;
8205 zcmixer->newtrack = NULL;
8206 }
8207
8208 zcmusic = zcmusic_load_for_quest(DMaps[currdmap].tmusic, qstpath);
8209 zcmixer->newtrack = zcmusic;
8210
8211 if (zcmusic != NULL)
8212 {
8213 zc_stop_midi();
8214 strcpy(tfile, DMaps[currdmap].tmusic);
8215 zcmusic_play(zcmusic, emusic_volume);
8216 int32_t temptracks = 0;
8217 temptracks = zcmusic_get_tracks(zcmusic);
8218 temptracks = (temptracks < 2) ? 1 : temptracks;
8219 ttrack = vbound(DMaps[currdmap].tmusictrack, 0, temptracks - 1);
8220 zcmusic_change_track(zcmusic, ttrack);
8221 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8222 }
8223 else
8224 {
8225 tfile[0] = 0;
8226 domidi = true;
8227 }
8228 }
8229 }
8230 }
8231 else
8232 {
8233 if (DMaps[currdmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[currdmap].tmusic) != 0)
8234 {
8235 FFCore.play_enh_music_crossfade(NULL, DMaps[currdmap].tmusictrack, DMaps[currdmap].tmusic_xfade_in, fadeoutframes);
8236 }
8237 else
8238 {
8239 domidi = true;
8240 }
8241 }
8242
8243 if(domidi)
8244 {
8245 int32_t m=DMaps[currdmap].midi;
8246
8247 switch(m)
8248 {
8249 case 1:
8250 jukebox(ZC_MIDI_OVERWORLD);
8251 break;
8252
8253 case 2:
8254 jukebox(ZC_MIDI_DUNGEON);
8255 break;
8256
8257 case 3:
8258 jukebox(ZC_MIDI_LEVEL9);
8259 break;
8260
8261 default:
8262 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8263 jukebox(m+MIDIOFFSET_DMAP);
8264 else
8265 music_stop();
8266 }
8267 }
8268 16 }
8269
8270 15754 void playLevelMusic()
8271 {
8272
1/2
✓ Branch 0 taken 15754 times.
✗ Branch 1 not taken.
15754 if (is_headless())
8273 15754 return;
8274
8275 int32_t m=tmpscr->screen_midi;
8276
8277 switch(m)
8278 {
8279 case -2:
8280 music_stop();
8281 break;
8282
8283 case -1:
8284 play_DmapMusic();
8285 break;
8286
8287 case 1:
8288 jukebox(ZC_MIDI_OVERWORLD);
8289 break;
8290
8291 case 2:
8292 jukebox(ZC_MIDI_DUNGEON);
8293 break;
8294
8295 case 3:
8296 jukebox(ZC_MIDI_LEVEL9);
8297 break;
8298
8299 default:
8300 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8301 jukebox(m+MIDIOFFSET_MAPSCR);
8302 else
8303 music_stop();
8304 }
8305 15754 }
8306
8307 116 void master_volume(int32_t dv,int32_t mv)
8308 {
8309
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
116 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8310
8311
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
✗ Branch 7 not taken.
116 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8312
8313
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 116 times.
116 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8314 116 int32_t temp_vol = midi_volume;
8315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
116 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8316 116 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8317 116 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8318 116 }
8319
8320 /*****************/
8321 /***** SFX *****/
8322 /*****************/
8323
8324 // array of voices, one for each sfx sample in the data file
8325 // 0+ = voice #
8326 // -1 = voice not allocated
8327 116 void Z_init_sound()
8328 {
8329
2/2
✓ Branch 0 taken 29696 times.
✓ Branch 1 taken 116 times.
29812 for(int32_t i=0; i<WAV_COUNT; i++)
8330 29696 sfx_voice[i]=-1;
8331
8332 116 const char* midis[ZC_MIDI_COUNT] = {
8333 "assets/dungeon.mid",
8334 "assets/ending.mid",
8335 "assets/gameover.mid",
8336 "assets/level9.mid",
8337 "assets/overworld.mid",
8338 "assets/title.mid",
8339 "assets/triforce.mid",
8340 };
8341
2/2
✓ Branch 0 taken 812 times.
✓ Branch 1 taken 116 times.
928 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8342 {
8343 812 tunes[i].data = load_midi(midis[i]);
8344
1/2
✓ Branch 0 taken 812 times.
✗ Branch 1 not taken.
812 if (!tunes[i].data)
8345 Z_error_fatal("Missing required file %s\n", midis[i]);
8346 812 }
8347
8348
2/2
✓ Branch 0 taken 29232 times.
✓ Branch 1 taken 116 times.
29348 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8349 29232 tunes[ZC_MIDI_COUNT+j].data=NULL;
8350
8351 116 master_volume(digi_volume,midi_volume);
8352 116 }
8353
8354 // returns number of voices currently allocated
8355 int32_t sfx_count()
8356 {
8357 int32_t c=0;
8358
8359 for(int32_t i=0; i<WAV_COUNT; i++)
8360 if(sfx_voice[i]!=-1)
8361 ++c;
8362
8363 return c;
8364 }
8365
8366 // clean up finished samples
8367 9217426 void sfx_cleanup()
8368 {
8369
2/2
✓ Branch 0 taken 2359661056 times.
✓ Branch 1 taken 9217426 times.
2368878482 for(int32_t i=0; i<WAV_COUNT; i++)
8370
3/4
✓ Branch 0 taken 619381 times.
✓ Branch 1 taken 2359041675 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 619381 times.
2360280437 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8371 {
8372 619381 deallocate_voice(sfx_voice[i]);
8373 619381 sfx_voice[i]=-1;
8374 619381 }
8375 9217426 }
8376
8377 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8378 // if a voice is already allocated (and/or playing), then it just returns true
8379 // Returns true: voice is allocated
8380 // false: unsuccessful
8381 963799 bool sfx_init(int32_t index)
8382 {
8383 // check index
8384
3/4
✓ Branch 0 taken 721410 times.
✓ Branch 1 taken 242389 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 721410 times.
963799 if(index<=0 || index>=WAV_COUNT)
8385 242389 return false;
8386
8387
2/2
✓ Branch 0 taken 102011 times.
✓ Branch 1 taken 619399 times.
721410 if(sfx_voice[index]==-1)
8388 {
8389
2/2
✓ Branch 0 taken 209876 times.
✓ Branch 1 taken 409523 times.
619399 if(sfxdat)
8390 {
8391
1/2
✓ Branch 0 taken 209876 times.
✗ Branch 1 not taken.
209876 if(index<Z35)
8392 {
8393 209876 sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[index].dat);
8394 209876 }
8395 else
8396 {
8397 sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[Z35].dat);
8398 }
8399 209876 }
8400 else
8401 {
8402 409523 sfx_voice[index]=allocate_voice(&customsfxdata[index]);
8403 }
8404
8405 619399 int32_t temp_volume = sfx_volume;
8406
2/4
✓ Branch 0 taken 619399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 619399 times.
✗ Branch 3 not taken.
619399 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8407 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8408 619399 voice_set_volume(sfx_voice[index], temp_volume);
8409 619399 }
8410
8411 721410 return sfx_voice[index] != -1;
8412 963799 }
8413
8414 int32_t sfx_get_default_freq(int32_t index)
8415 {
8416 if (sfxdat)
8417 {
8418 if (index < Z35)
8419 {
8420 return ((SAMPLE*)sfxdata[index].dat)->freq;
8421 }
8422 else
8423 {
8424 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8425 }
8426 }
8427 else
8428 {
8429 return customsfxdata[index].freq;
8430 }
8431 }
8432
8433 int32_t sfx_get_length(int32_t index)
8434 {
8435 if (sfxdat)
8436 {
8437 if (index < Z35)
8438 {
8439 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8440 }
8441 else
8442 {
8443 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8444 }
8445 }
8446 else
8447 {
8448 return int32_t(customsfxdata[index].len);
8449 }
8450 }
8451
8452 // plays an sfx sample
8453 963799 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8454 {
8455
2/2
✓ Branch 0 taken 721410 times.
✓ Branch 1 taken 242389 times.
963799 if(!sfx_init(index))
8456 242389 return;
8457
1/2
✓ Branch 0 taken 721410 times.
✗ Branch 1 not taken.
721410 if (!is_headless())
8458 {
8459 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8460 voice_set_pan(sfx_voice[index], pan);
8461
8462 // Only used by ZScript currently
8463 if (freq <= -1)
8464 {
8465 freq = sfx_get_default_freq(index);
8466 }
8467 voice_set_frequency(sfx_voice[index], freq);
8468
8469 // Only used by ZScript currently
8470 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8471 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8472 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8473 voice_set_volume(sfx_voice[index], temp_volume);
8474
8475 int32_t pos = voice_get_position(sfx_voice[index]);
8476
8477 if (restart) voice_set_position(sfx_voice[index], 0);
8478
8479 if (pos <= 0)
8480 voice_start(sfx_voice[index]);
8481 }
8482
8483
3/4
✓ Branch 0 taken 397878 times.
✓ Branch 1 taken 323532 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 397878 times.
721410 if (restart && replay_is_debug())
8484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 397878 times.
397878 replay_step_comment(fmt::format("sfx {}", sfx_string[index]));
8485 963799 }
8486
8487 // true if sfx is allocated
8488 68051 bool sfx_allocated(int32_t index)
8489 {
8490
3/4
✓ Branch 0 taken 9922 times.
✓ Branch 1 taken 58129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9922 times.
68051 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8491 }
8492
8493 // start it (in loop mode) if it's not already playing,
8494 // otherwise adjust it to play in loop mode -DD
8495 55173 void cont_sfx(int32_t index)
8496 {
8497
1/2
✓ Branch 0 taken 55173 times.
✗ Branch 1 not taken.
55173 if (is_headless())
8498 55173 return;
8499
8500 if(!sfx_init(index))
8501 {
8502 return;
8503 }
8504
8505 if(voice_get_position(sfx_voice[index])<=0)
8506 {
8507 voice_set_position(sfx_voice[index],0);
8508 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8509 voice_start(sfx_voice[index]);
8510 }
8511 else
8512 {
8513 adjust_sfx(index, 128, true);
8514 }
8515 55173 }
8516
8517 // adjust parameters while playing
8518 4075 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8519 {
8520
4/6
✓ Branch 0 taken 2315 times.
✓ Branch 1 taken 1760 times.
✓ Branch 2 taken 2315 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2315 times.
4075 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8521 4075 return;
8522
8523 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8524 voice_set_pan(sfx_voice[index],pan);
8525 4075 }
8526
8527 // pauses a voice
8528 1725 void pause_sfx(int32_t index)
8529 {
8530
3/6
✓ Branch 0 taken 1725 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1725 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1725 times.
1725 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8531 voice_stop(sfx_voice[index]);
8532 1725 }
8533
8534 // resumes a voice
8535 747 void resume_sfx(int32_t index)
8536 {
8537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
747 if (is_headless())
8538 747 return;
8539
8540 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8541 voice_start(sfx_voice[index]);
8542 747 }
8543
8544 // pauses all active voices
8545 448 void pause_all_sfx()
8546 {
8547
2/2
✓ Branch 0 taken 114688 times.
✓ Branch 1 taken 448 times.
115136 for(int32_t i=0; i<WAV_COUNT; i++)
8548
2/2
✓ Branch 0 taken 114687 times.
✓ Branch 1 taken 1 times.
114689 if(sfx_voice[i]!=-1)
8549 1 voice_stop(sfx_voice[i]);
8550 448 }
8551
8552 // resumes all paused voices
8553 434 void resume_all_sfx()
8554 {
8555
2/2
✓ Branch 0 taken 111104 times.
✓ Branch 1 taken 434 times.
111538 for(int32_t i=0; i<WAV_COUNT; i++)
8556
1/2
✓ Branch 0 taken 111104 times.
✗ Branch 1 not taken.
111104 if(sfx_voice[i]!=-1)
8557 voice_start(sfx_voice[i]);
8558 434 }
8559
8560 // stops an sfx and deallocates the voice
8561 7462095 void stop_sfx(int32_t index)
8562 {
8563
3/4
✓ Branch 0 taken 6277029 times.
✓ Branch 1 taken 1185066 times.
✓ Branch 2 taken 6277029 times.
✗ Branch 3 not taken.
7462095 if(index<=0 || index>=WAV_COUNT)
8564 1185066 return;
8565
8566
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6277017 times.
6277029 if(sfx_voice[index]!=-1)
8567 {
8568 12 deallocate_voice(sfx_voice[index]);
8569 12 sfx_voice[index]=-1;
8570 12 }
8571 7462095 }
8572
8573 // Stops SFX played by Hero's item of the given family
8574 128638 void stop_item_sfx(int32_t family)
8575 {
8576 128638 int32_t id=current_item_id(family);
8577
8578
2/2
✓ Branch 0 taken 128083 times.
✓ Branch 1 taken 555 times.
128638 if(id<0)
8579 128083 return;
8580
8581 555 stop_sfx(itemsbuf[id].usesound);
8582 128638 }
8583
8584 3222 void kill_sfx()
8585 {
8586
2/2
✓ Branch 0 taken 824832 times.
✓ Branch 1 taken 3222 times.
828054 for(int32_t i=0; i<WAV_COUNT; i++)
8587
2/2
✓ Branch 0 taken 824826 times.
✓ Branch 1 taken 6 times.
824838 if(sfx_voice[i]!=-1)
8588 {
8589 6 deallocate_voice(sfx_voice[i]);
8590 6 sfx_voice[i]=-1;
8591 6 }
8592 3222 }
8593
8594 659526 int32_t pan(int32_t x)
8595 {
8596
1/4
✓ Branch 0 taken 659526 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
659526 switch(pan_style)
8597 {
8598 case 0:
8599 return 128;
8600
8601 case 1:
8602 659526 return vbound((x>>1)+68,0,255);
8603
8604 case 2:
8605 return vbound(((x*3)>>2)+36,0,255);
8606 }
8607
8608 return vbound(x,0,255);
8609 659526 }
8610
8611 /*******************************/
8612 /******* Input Handlers ********/
8613 /*******************************/
8614
8615 25091568 bool joybtn(int32_t b)
8616 {
8617
1/2
✓ Branch 0 taken 25091568 times.
✗ Branch 1 not taken.
25091568 if(b == 0)
8618 return false;
8619
1/2
✓ Branch 0 taken 25091568 times.
✗ Branch 1 not taken.
25091568 if (b-1 >= joy[joystick_index].num_buttons)
8620 25091568 return false;
8621
8622 return joy[joystick_index].button[b-1].b !=0;
8623 25091568 }
8624
8625 bool joystick(int32_t s)
8626 {
8627 if(s < 0)
8628 return false;
8629 if (s >= joy[joystick_index].num_sticks)
8630 return false;
8631
8632 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8633 {
8634 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8635 return true;
8636 }
8637 return false;
8638 }
8639
8640 const char* joybtn_name(int32_t b)
8641 {
8642 if (b <= 0 || b > joy[joystick_index].num_buttons)
8643 return "";
8644
8645 return joy[joystick_index].button[b-1].name;
8646 }
8647
8648 const char* joystick_name(int32_t s)
8649 {
8650 if (s < 0 || s >= joy[joystick_index].num_sticks)
8651 return "";
8652
8653 return joy[joystick_index].stick[s].name;
8654 }
8655
8656 int32_t next_press_key();
8657
8658 int32_t next_joy_input(bool buttons)
8659 {
8660 clear_keybuf();
8661
8662 //first, we need to wait until they're pressing no buttons
8663 for(;;)
8664 {
8665 if(keypressed())
8666 {
8667 switch(readkey()>>8)
8668 {
8669 case KEY_ESC:
8670 return -1;
8671
8672 case KEY_SPACE:
8673 return 0;
8674 }
8675 }
8676
8677 poll_joystick();
8678 bool done = true;
8679
8680 if (buttons)
8681 {
8682 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8683 {
8684 if(joybtn(i)) done = false;
8685 }
8686 }
8687 else
8688 {
8689 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8690 {
8691 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8692 return -2;
8693 }
8694 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8695 {
8696 if(joystick(i)) done = false;
8697 }
8698 }
8699
8700 if(done) break;
8701 rest(1);
8702 }
8703
8704 //now, we need to wait for them to press any button
8705 for(;;)
8706 {
8707 if(keypressed())
8708 {
8709 switch(readkey()>>8)
8710 {
8711 case KEY_ESC:
8712 return -1;
8713
8714 case KEY_SPACE:
8715 return 0;
8716 }
8717 }
8718
8719 poll_joystick();
8720
8721 if (buttons)
8722 {
8723 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8724 {
8725 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8726 return -2;
8727 }
8728 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8729 {
8730 if(joybtn(i))
8731 return i;
8732 }
8733 }
8734 else
8735 {
8736 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8737 {
8738 if(joystick(i))
8739 return i;
8740 }
8741 }
8742 rest(1);
8743 }
8744 }
8745
8746 1209106 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8747 {
8748
2/2
✓ Branch 0 taken 1204755 times.
✓ Branch 1 taken 4351 times.
1209106 bool ret = btn && !flag;
8749 1209106 flag = rawbtn;
8750
8751 1209106 return ret;
8752 }
8753 190783826 static bool rButton(bool &btn, bool &flag)
8754 {
8755
2/2
✓ Branch 0 taken 183940697 times.
✓ Branch 1 taken 6843129 times.
190783826 bool ret = btn && !flag;
8756 190783826 flag = btn;
8757
8758 190783826 return ret;
8759 }
8760 2888422 static bool rButtonPeek(bool btn, bool flag)
8761 {
8762
2/2
✓ Branch 0 taken 2685421 times.
✓ Branch 1 taken 203001 times.
2888422 if(!btn)
8763 {
8764 2685421 return false;
8765 }
8766
2/2
✓ Branch 0 taken 17917 times.
✓ Branch 1 taken 185084 times.
203001 else if(!flag)
8767 {
8768 17917 return true;
8769 }
8770
8771 185084 return false;
8772 2888422 }
8773
8774 // Updated only by keyboard/gamepad.
8775 // If in replay mode, this is set directly by the replay system.
8776 // This should never be read from directly - use control_state instead.
8777 bool raw_control_state[ZC_CONTROL_STATES];
8778
8779 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8780 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8781 // lasts until the next call to load_control_state.
8782 bool control_state[ZC_CONTROL_STATES];
8783 bool disable_control[ZC_CONTROL_STATES];
8784 bool drunk_toggle_state[11];
8785 bool disabledKeys[127];
8786 bool KeyInput[127];
8787 bool KeyPress[127];
8788
8789 bool key_current_frame[127];
8790 bool key_previous_frame[127];
8791
8792 static bool key_system[127];
8793 static bool key_system_previous[127];
8794 static bool key_system_press[127];
8795
8796 bool button_press[ZC_CONTROL_STATES];
8797 bool button_hold[ZC_CONTROL_STATES];
8798
8799 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8800 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8801 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8802 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8803 #define STICK_PRECISION 56 //define your own sensitivity
8804
8805 7800197 void load_control_state()
8806 {
8807 7800197 load_control_called_this_frame = true;
8808
8809
2/2
✓ Branch 0 taken 4833663 times.
✓ Branch 1 taken 2966534 times.
7800197 if (replay_version_check(8, 11))
8810 {
8811
2/2
✓ Branch 0 taken 53397612 times.
✓ Branch 1 taken 2966534 times.
56364146 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8812 53397612 down_control_states[i] = raw_control_state[i];
8813 2966534 }
8814
8815
1/2
✓ Branch 0 taken 7800197 times.
✗ Branch 1 not taken.
7800197 if (!replay_is_replaying())
8816 {
8817 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8818 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8819 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8820 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8821 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8822 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8823 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8824 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8825 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8826 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8827 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8828 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8829 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8830 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8831
8832 if(num_joysticks != 0)
8833 {
8834 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8835 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8836 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8837 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8838 // zprint2("Detected %d joysticks... %d%d%d%d\n", num_joysticks, raw_control_state[14]?1:0, raw_control_state[15]?1:0, raw_control_state[16]?1:0, raw_control_state[17]?1:0);
8839 }
8840 else
8841 {
8842 raw_control_state[14] = false;
8843 raw_control_state[15] = false;
8844 raw_control_state[16] = false;
8845 raw_control_state[17] = false;
8846 // zprint2("Detected 0 joysticks... clearing inputaxis values.\n");
8847 }
8848 }
8849
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7800194 times.
7800197 if (replay_is_active())
8850 {
8851
2/2
✓ Branch 0 taken 1015215 times.
✓ Branch 1 taken 6784979 times.
7800194 if (replay_get_version() < 3)
8852 1015215 replay_poll();
8853
3/4
✓ Branch 0 taken 6784979 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5023604 times.
✓ Branch 3 taken 1761375 times.
6784979 else if (replay_is_replaying() && replay_get_version() < 6)
8854 1761375 replay_peek_input();
8855
3/4
✓ Branch 0 taken 5023604 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2057070 times.
✓ Branch 3 taken 2966534 times.
5023604 else if (replay_is_replaying() && replay_version_check(8, 11))
8856 2966534 replay_peek_input();
8857
2/2
✓ Branch 0 taken 6696883 times.
✓ Branch 1 taken 1103311 times.
7800194 if (replay_get_version() == 8)
8858 1103311 update_keys();
8859 7800194 }
8860
8861 // Some test replay files were made before a serious input bug was fixed, so instead
8862 // of re-doing them or tossing them out, just check for that zplay version.
8863
3/4
✓ Branch 0 taken 7800191 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 7678291 times.
7800197 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8864
2/2
✓ Branch 0 taken 140403438 times.
✓ Branch 1 taken 7800191 times.
148203629 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8865 {
8866 140403438 control_state[i] = raw_control_state[i];
8867
4/4
✓ Branch 0 taken 49487310 times.
✓ Branch 1 taken 90916128 times.
✓ Branch 2 taken 2410168 times.
✓ Branch 3 taken 47077142 times.
140403438 if (botched_input && !control_state[i])
8868 47077142 down_control_states[i] = false;
8869 140403438 }
8870 7800191 bool did_bad_cutscene_btn = false;
8871
2/2
✓ Branch 0 taken 7800191 times.
✓ Branch 1 taken 140403438 times.
148203629 for(int q = 0; q < 18; ++q)
8872
4/4
✓ Branch 0 taken 6463821 times.
✓ Branch 1 taken 133939617 times.
✓ Branch 2 taken 6463087 times.
✓ Branch 3 taken 734 times.
140404172 if(control_state[q] && !active_cutscene.can_button(q))
8873 {
8874 734 control_state[q] = false;
8875 734 did_bad_cutscene_btn = true;
8876 734 }
8877
2/2
✓ Branch 0 taken 7799676 times.
✓ Branch 1 taken 515 times.
7800191 if(did_bad_cutscene_btn)
8878 515 active_cutscene.error();
8879
8880 7800191 button_press[0]=rButton(control_state[0],button_hold[0]);
8881 7800191 button_press[1]=rButton(control_state[1],button_hold[1]);
8882 7800191 button_press[2]=rButton(control_state[2],button_hold[2]);
8883 7800191 button_press[3]=rButton(control_state[3],button_hold[3]);
8884 7800191 button_press[4]=rButton(control_state[4],button_hold[4]);
8885 7800191 button_press[5]=rButton(control_state[5],button_hold[5]);
8886 7800191 button_press[6]=rButton(control_state[6],button_hold[6]);
8887 7800191 button_press[7]=rButton(control_state[7],button_hold[7]);
8888 7800191 button_press[8]=rButton(control_state[8],button_hold[8]);
8889 7800191 button_press[9]=rButton(control_state[9],button_hold[9]);
8890 7800191 button_press[10]=rButton(control_state[10],button_hold[10]);
8891 7800191 button_press[11]=rButton(control_state[11],button_hold[11]);
8892 7800191 button_press[12]=rButton(control_state[12],button_hold[12]);
8893 7800191 button_press[13]=rButton(control_state[13],button_hold[13]);
8894 7800191 button_press[14]=rButton(control_state[14],button_hold[14]);
8895 7800191 button_press[15]=rButton(control_state[15],button_hold[15]);
8896 7800191 button_press[16]=rButton(control_state[16],button_hold[16]);
8897 7800191 button_press[17]=rButton(control_state[17],button_hold[17]);
8898 7800191 }
8899
8900 // Returns true if any game key is pressed. This is needed because keypressed()
8901 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8902 40246368 bool zc_key_pressed()
8903 //may also need to use zc_getrawkey
8904 {
8905
7/10
✓ Branch 0 taken 32594281 times.
✓ Branch 1 taken 7652087 times.
✓ Branch 2 taken 7652087 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7652087 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6395695 times.
✓ Branch 7 taken 6395695 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2461515 times.
42707883 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8906
4/6
✓ Branch 0 taken 6395695 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6395695 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4843598 times.
✓ Branch 5 taken 4843598 times.
6395695 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8907
4/6
✓ Branch 0 taken 4843598 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4843598 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3142868 times.
✓ Branch 5 taken 3142868 times.
4843598 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8908
4/6
✓ Branch 0 taken 3142868 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3142868 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2732021 times.
✓ Branch 5 taken 2732021 times.
3142868 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8909
1/2
✓ Branch 0 taken 2732021 times.
✗ Branch 1 not taken.
2732021 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8910
3/4
✓ Branch 0 taken 2612614 times.
✓ Branch 1 taken 119407 times.
✓ Branch 2 taken 2612614 times.
✗ Branch 3 not taken.
2732021 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8911
3/4
✓ Branch 0 taken 2493725 times.
✓ Branch 1 taken 118889 times.
✓ Branch 2 taken 2493725 times.
✗ Branch 3 not taken.
2612614 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8912
3/4
✓ Branch 0 taken 2478580 times.
✓ Branch 1 taken 15145 times.
✓ Branch 2 taken 2478580 times.
✗ Branch 3 not taken.
2493725 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8913
3/4
✓ Branch 0 taken 2465081 times.
✓ Branch 1 taken 13499 times.
✓ Branch 2 taken 2465081 times.
✗ Branch 3 not taken.
2478580 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8914
3/4
✓ Branch 0 taken 2462591 times.
✓ Branch 1 taken 2490 times.
✓ Branch 2 taken 2462591 times.
✗ Branch 3 not taken.
2465081 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8915
3/4
✓ Branch 0 taken 2462373 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 2462373 times.
✗ Branch 3 not taken.
2462591 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8916
3/4
✓ Branch 0 taken 2461534 times.
✓ Branch 1 taken 839 times.
✓ Branch 2 taken 2461534 times.
✗ Branch 3 not taken.
2462373 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8917
2/4
✓ Branch 0 taken 2461534 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461534 times.
✗ Branch 3 not taken.
2461534 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8918
2/2
✓ Branch 0 taken 2461515 times.
✓ Branch 1 taken 19 times.
2461534 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8919 72013217 return true;
8920
8921 2461515 return false;
8922 9286170 }
8923
8924 149985342 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8925 {
8926 149985342 bool ret = false, drunkstate = false, rawret = false;;
8927 149985342 bool* flag = &down_control_states[btn];
8928
2/7
✓ Branch 0 taken 140689835 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 9295507 times.
149985342 switch(btn)
8929 {
8930 case btnF12:
8931 ret = zc_getkey(KEY_F12, ignoreDisable);
8932 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8933 eatEntirely = false;
8934 break;
8935 case btnF11:
8936 ret = zc_getkey(KEY_F11, ignoreDisable);
8937 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8938 eatEntirely = false;
8939 break;
8940 case btnF5:
8941 ret = zc_getkey(KEY_F5, ignoreDisable);
8942 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8943 eatEntirely = false;
8944 break;
8945 case btnQ:
8946 ret = zc_getkey(KEY_Q, ignoreDisable);
8947 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8948 eatEntirely = false;
8949 break;
8950 case btnI:
8951 ret = zc_getkey(KEY_I, ignoreDisable);
8952 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8953 eatEntirely = false;
8954 break;
8955 case btnM:
8956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9295507 times.
9295507 if(FFCore.kb_typing_mode) return false;
8957 9295507 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8958 9295507 eatEntirely = false;
8959 9295507 break;
8960 default: //control_state[] index
8961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140689835 times.
140689835 if(FFCore.kb_typing_mode) return false;
8962
5/6
✓ Branch 0 taken 139890056 times.
✓ Branch 1 taken 799779 times.
✓ Branch 2 taken 2226418 times.
✓ Branch 3 taken 137663638 times.
✓ Branch 4 taken 2226418 times.
✗ Branch 5 not taken.
140689835 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8963
2/2
✓ Branch 0 taken 8034686 times.
✓ Branch 1 taken 132655149 times.
140689835 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8964
4/4
✓ Branch 0 taken 126550808 times.
✓ Branch 1 taken 14139027 times.
✓ Branch 2 taken 3004 times.
✓ Branch 3 taken 14136023 times.
154828862 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8965 140689835 rawret = raw_control_state[btn];
8966 140689835 }
8967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149985342 times.
149985342 assert(flag);
8968
2/2
✓ Branch 0 taken 95507426 times.
✓ Branch 1 taken 54477916 times.
149985342 if(press)
8969 {
8970
2/2
✓ Branch 0 taken 2888422 times.
✓ Branch 1 taken 51589494 times.
54477916 if(peek)
8971 2888422 ret = rButtonPeek(ret, *flag);
8972
2/2
✓ Branch 0 taken 50380388 times.
✓ Branch 1 taken 1209106 times.
51589494 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8973 1209106 else ret = rButton(ret, *flag, rawret);
8974 54477916 }
8975
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 149985342 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
149985342 if(eatEntirely && ret) control_state[btn] = false;
8976
3/4
✓ Branch 0 taken 112368447 times.
✓ Branch 1 taken 37616895 times.
✓ Branch 2 taken 112368447 times.
✗ Branch 3 not taken.
149985342 if(drunk && drunkstate) ret = !ret;
8977 149985342 return ret;
8978 149985342 }
8979
8980 7464732 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8981 {
8982 7464732 byte ret = 0;
8983
2/2
✓ Branch 0 taken 5485975 times.
✓ Branch 1 taken 1978757 times.
7464732 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8984
2/2
✓ Branch 0 taken 7333918 times.
✓ Branch 1 taken 130814 times.
7464732 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8985
2/2
✓ Branch 0 taken 7334043 times.
✓ Branch 1 taken 130689 times.
7464732 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8986
2/2
✓ Branch 0 taken 7334043 times.
✓ Branch 1 taken 130689 times.
7464732 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8987
2/2
✓ Branch 0 taken 7334043 times.
✓ Branch 1 taken 130689 times.
7464732 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8988
2/2
✓ Branch 0 taken 7334043 times.
✓ Branch 1 taken 130689 times.
7464732 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8989
2/2
✓ Branch 0 taken 7334043 times.
✓ Branch 1 taken 130689 times.
7464732 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8990
2/2
✓ Branch 0 taken 7334043 times.
✓ Branch 1 taken 130689 times.
7464732 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8991 7464732 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8992 }
8993
8994 1114 byte checkIntBtnVal(byte intbtn, byte vals)
8995 {
8996 1114 return intbtn&vals;
8997 }
8998
8999 1767371 bool Up()
9000 {
9001 1767371 return getInput(btnUp);
9002 }
9003 147199 bool Down()
9004 {
9005 147199 return getInput(btnDown);
9006 }
9007 257607 bool Left()
9008 {
9009 257607 return getInput(btnLeft);
9010 }
9011 286801 bool Right()
9012 {
9013 286801 return getInput(btnRight);
9014 }
9015 164850 bool cAbtn()
9016 {
9017 164850 return getInput(btnA);
9018 }
9019 1411781 bool cBbtn()
9020 {
9021 1411781 return getInput(btnB);
9022 }
9023 bool cSbtn()
9024 {
9025 return getInput(btnS);
9026 }
9027 68744 bool cLbtn()
9028 {
9029 68744 return getInput(btnL);
9030 }
9031 68744 bool cRbtn()
9032 {
9033 68744 return getInput(btnR);
9034 }
9035 bool cPbtn()
9036 {
9037 return getInput(btnP);
9038 }
9039 bool cEx1btn()
9040 {
9041 return getInput(btnEx1);
9042 }
9043 bool cEx2btn()
9044 {
9045 return getInput(btnEx2);
9046 }
9047 bool cEx3btn()
9048 {
9049 return getInput(btnEx3);
9050 }
9051 bool cEx4btn()
9052 {
9053 return getInput(btnEx4);
9054 }
9055 bool AxisUp()
9056 {
9057 return getInput(btnAxisUp);
9058 }
9059 bool AxisDown()
9060 {
9061 return getInput(btnAxisDown);
9062 }
9063 bool AxisLeft()
9064 {
9065 return getInput(btnAxisLeft);
9066 }
9067 bool AxisRight()
9068 {
9069 return getInput(btnAxisRight);
9070 }
9071
9072 bool cMbtn()
9073 {
9074 return getInput(btnM);
9075 }
9076 bool cF12()
9077 {
9078 return getInput(btnF12);
9079 }
9080 bool cF11()
9081 {
9082 return getInput(btnF11);
9083 }
9084 bool cF5()
9085 {
9086 return getInput(btnF5);
9087 }
9088 bool cQ()
9089 {
9090 return getInput(btnQ);
9091 }
9092 bool cI()
9093 {
9094 return getInput(btnI);
9095 }
9096
9097 130270 bool rUp()
9098 {
9099 130270 return getInput(btnUp, true);
9100 }
9101 130174 bool rDown()
9102 {
9103 130174 return getInput(btnDown, true);
9104 }
9105 130122 bool rLeft()
9106 {
9107 130122 return getInput(btnLeft, true);
9108 }
9109 129657 bool rRight()
9110 {
9111 129657 return getInput(btnRight, true);
9112 }
9113 1295 bool rAbtn()
9114 {
9115 1295 return getInput(btnA, true);
9116 }
9117 1295 bool rBbtn()
9118 {
9119 1295 return getInput(btnB, true);
9120 }
9121 7396546 bool rSbtn()
9122 {
9123 7396546 return getInput(btnS, true);
9124 }
9125 9286170 bool rMbtn()
9126 {
9127 9286170 return getInput(btnM, true);
9128 }
9129 129441 bool rLbtn()
9130 {
9131 129441 return getInput(btnL, true);
9132 }
9133 129436 bool rRbtn()
9134 {
9135 129436 return getInput(btnR, true);
9136 }
9137 7333010 bool rPbtn()
9138 {
9139 7333010 return getInput(btnP, true);
9140 }
9141 bool rEx1btn()
9142 {
9143 return getInput(btnEx1, true);
9144 }
9145 bool rEx2btn()
9146 {
9147 return getInput(btnEx2, true);
9148 }
9149 139523 bool rEx3btn()
9150 {
9151 139523 return getInput(btnEx3, true);
9152 }
9153 139523 bool rEx4btn()
9154 {
9155 139523 return getInput(btnEx4, true);
9156 }
9157 bool rAxisUp()
9158 {
9159 return getInput(btnAxisUp, true);
9160 }
9161 bool rAxisDown()
9162 {
9163 return getInput(btnAxisDown, true);
9164 }
9165 bool rAxisLeft()
9166 {
9167 return getInput(btnAxisLeft, true);
9168 }
9169 bool rAxisRight()
9170 {
9171 return getInput(btnAxisRight, true);
9172 }
9173
9174 bool rF11()
9175 {
9176 return getInput(btnF11, true);
9177 }
9178 bool rQ()
9179 {
9180 return getInput(btnQ, true);
9181 }
9182 bool rI()
9183 {
9184 return getInput(btnI, true);
9185 }
9186
9187 18226299 bool DrunkUp()
9188 {
9189 18226299 return getInput(btnUp, false, true);
9190 }
9191 16889254 bool DrunkDown()
9192 {
9193 16889254 return getInput(btnDown, false, true);
9194 }
9195 10288449 bool DrunkLeft()
9196 {
9197 10288449 return getInput(btnLeft, false, true);
9198 }
9199 8834137 bool DrunkRight()
9200 {
9201 8834137 return getInput(btnRight, false, true);
9202 }
9203 8035302 bool DrunkcAbtn()
9204 {
9205 8035302 return getInput(btnA, false, true);
9206 }
9207 8016904 bool DrunkcBbtn()
9208 {
9209 8016904 return getInput(btnB, false, true);
9210 }
9211 7263880 bool DrunkcEx1btn()
9212 {
9213 7263880 return getInput(btnEx1, false, true);
9214 }
9215 7263900 bool DrunkcEx2btn()
9216 {
9217 7263900 return getInput(btnEx2, false, true);
9218 }
9219 bool DrunkcSbtn()
9220 {
9221 return getInput(btnS, false, true);
9222 }
9223 bool DrunkcMbtn()
9224 {
9225 return getInput(btnM, false, true);
9226 }
9227 bool DrunkcLbtn()
9228 {
9229 return getInput(btnL, false, true);
9230 }
9231 bool DrunkcRbtn()
9232 {
9233 return getInput(btnR, false, true);
9234 }
9235 bool DrunkcPbtn()
9236 {
9237 return getInput(btnP, false, true);
9238 }
9239
9240 bool DrunkrUp()
9241 {
9242 return getInput(btnUp, true, true);
9243 }
9244 bool DrunkrDown()
9245 {
9246 return getInput(btnDown, true, true);
9247 }
9248 bool DrunkrLeft()
9249 {
9250 return getInput(btnLeft, true, true);
9251 }
9252 bool DrunkrRight()
9253 {
9254 return getInput(btnRight, true, true);
9255 }
9256 6081752 bool DrunkrAbtn()
9257 {
9258 6081752 return getInput(btnA, true, true);
9259 }
9260 6098573 bool DrunkrBbtn()
9261 {
9262 6098573 return getInput(btnB, true, true);
9263 }
9264 71669 bool DrunkrEx1btn()
9265 {
9266 71669 return getInput(btnEx1, true, true);
9267 }
9268 71662 bool DrunkrEx2btn()
9269 {
9270 71662 return getInput(btnEx2, true, true);
9271 }
9272 bool DrunkrEx3btn()
9273 {
9274 return getInput(btnEx3, true, true);
9275 }
9276 bool DrunkrEx4btn()
9277 {
9278 return getInput(btnEx4, true, true);
9279 }
9280 bool DrunkrSbtn()
9281 {
9282 return getInput(btnS, true, true);
9283 }
9284 bool DrunkrMbtn()
9285 {
9286 return getInput(btnM, true, true);
9287 }
9288 6689226 bool DrunkrLbtn()
9289 {
9290 6689226 return getInput(btnL, true, true);
9291 }
9292 6685751 bool DrunkrRbtn()
9293 {
9294 6685751 return getInput(btnR, true, true);
9295 }
9296 bool DrunkrPbtn()
9297 {
9298 return getInput(btnP, true, true);
9299 }
9300
9301 9337 void eat_buttons()
9302 {
9303 9337 getInput(btnA, true, false, true);
9304 9337 getInput(btnB, true, false, true);
9305 9337 getInput(btnS, true, false, true);
9306 9337 getInput(btnM, true, false, true);
9307 9337 getInput(btnL, true, false, true);
9308 9337 getInput(btnR, true, false, true);
9309 9337 getInput(btnP, true, false, true);
9310 9337 getInput(btnEx1, true, false, true);
9311 9337 getInput(btnEx2, true, false, true);
9312 9337 getInput(btnEx3, true, false, true);
9313 9337 getInput(btnEx4, true, false, true);
9314 9337 }
9315
9316 // Is true for the _first frame_ of a key press.
9317 // But! it is possible that a script manually sets the value of KeyPress,
9318 // in which case it will be restored to the "true" value based on `key_current_frame`
9319 // and `key_previous_frame` on the next frame.
9320 14 bool zc_readkey(int32_t k, bool ignoreDisable)
9321 {
9322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(ignoreDisable) return KeyPress[k];
9323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 switch(k)
9324 {
9325 case KEY_F7:
9326 case KEY_F8:
9327 case KEY_F9:
9328 return KeyPress[k];
9329
9330 default:
9331
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 return KeyPress[k] && !disabledKeys[k];
9332 }
9333 14 }
9334
9335 // Is true for _every frame_ a key is held down.
9336 // But! it is possible that a script manually sets the value of KeyInput,
9337 // in which case it will be restored to the "true" value based on `key_current_frame`
9338 // on the next frame.
9339 bool zc_getkey(int32_t k, bool ignoreDisable)
9340 {
9341 if(ignoreDisable) return KeyInput[k];
9342 switch(k)
9343 {
9344 case KEY_F7:
9345 case KEY_F8:
9346 case KEY_F9:
9347 return KeyInput[k];
9348
9349 default:
9350 return KeyInput[k] && !disabledKeys[k];
9351 }
9352 }
9353
9354 // Reads (and then clears) the current frame key state directly.
9355 // Scripts can also modify `key_current_frame`.
9356 303 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9357 {
9358
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 301 times.
303 if(zc_getrawkey(k, ignoreDisable))
9359 {
9360 2 _key[k]=key[k]=key_current_frame[k]=0;
9361 2 return true;
9362 }
9363 301 _key[k]=key[k]=key_current_frame[k]=0;
9364 301 return false;
9365 303 }
9366
9367 // Reads the current frame key state directly.
9368 // Scripts can also modify `key_current_frame`.
9369 63246281 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9370 {
9371
2/2
✓ Branch 0 taken 53960083 times.
✓ Branch 1 taken 9286198 times.
63246281 if(ignoreDisable) return key_current_frame[k];
9372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286198 times.
9286198 switch(k)
9373 {
9374 case KEY_F7:
9375 case KEY_F8:
9376 case KEY_F9:
9377 return key_current_frame[k];
9378
9379 default:
9380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9286198 times.
9286198 return key_current_frame[k] && !disabledKeys[k];
9381 }
9382 63246281 }
9383
9384 // Only used for a handful of keys, like tilde and Function keys.
9385 // This state is never read within the game.
9386 // It exists so that all keyboard input still functions during replay,
9387 // without inadvertently doing things like toggling throttling if the player
9388 // presses ~
9389 9286170 bool zc_get_system_key(int32_t k)
9390 {
9391 9286170 return key_system[k];
9392 }
9393
9394 // True for the _first_ frame of a key press.
9395 83575530 bool zc_read_system_key(int32_t k)
9396 {
9397 83575530 return key_system_press[k];
9398 }
9399
9400 1179343590 bool is_system_key(int32_t k)
9401 {
9402
2/2
✓ Branch 0 taken 1095768060 times.
✓ Branch 1 taken 83575530 times.
1179343590 switch (k)
9403 {
9404 case KEY_BACKQUOTE:
9405 case KEY_CLOSEBRACE:
9406 case KEY_END:
9407 case KEY_HOME:
9408 case KEY_OPENBRACE:
9409 case KEY_PGDN:
9410 case KEY_PGUP:
9411 case KEY_TAB:
9412 case KEY_TILDE:
9413 83575530 return true;
9414 }
9415 1095768060 return is_Fkey(k);
9416 1179343590 }
9417
9418 9286170 void update_system_keys()
9419 {
9420
2/2
✓ Branch 0 taken 1179343590 times.
✓ Branch 1 taken 9286170 times.
1188629760 for (int32_t q = 0; q < 127; ++q)
9421 {
9422
2/2
✓ Branch 0 taken 195009570 times.
✓ Branch 1 taken 984334020 times.
1179343590 if (!is_system_key(q))
9423 984334020 continue;
9424
9425 195009570 key_system[q] = key[q];
9426
1/2
✓ Branch 0 taken 195009570 times.
✗ Branch 1 not taken.
195009570 key_system_press[q] = key_system[q] && !key_system_previous[q];
9427 195009570 key_system_previous[q] = key_system[q];
9428 195009570 }
9429 9286170 }
9430
9431 10389481 void update_keys()
9432 {
9433
2/2
✓ Branch 0 taken 1319464087 times.
✓ Branch 1 taken 10389481 times.
1329853568 for (int32_t q = 0; q < 127; ++q)
9434 {
9435 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9436
1/2
✓ Branch 0 taken 1319464087 times.
✗ Branch 1 not taken.
1319464087 if (!replay_is_replaying())
9437 key_current_frame[q] = key[q];
9438
9439
2/2
✓ Branch 0 taken 1309677917 times.
✓ Branch 1 taken 9786170 times.
1319464087 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9440 1319464087 KeyInput[q] = key_current_frame[q];
9441 1319464087 key_previous_frame[q] = key_current_frame[q];
9442 1319464087 }
9443 10389481 }
9444
9445 bool zc_disablekey(int32_t k, bool val)
9446 {
9447 switch(k)
9448 {
9449 case KEY_F7:
9450 case KEY_F8:
9451 case KEY_F9:
9452 return false;
9453
9454 default:
9455 disabledKeys[k] = val;
9456 return true;
9457 }
9458 }
9459
9460 void zc_putpixel(int32_t layer, int32_t x, int32_t y, int32_t cset, int32_t color, int32_t timer)
9461 {
9462 timer=timer;
9463 particles.add(new particle(zfix(x), zfix(y), layer, cset, color));
9464 }
9465